SELECT DISTINCT alternative
It's the kind of related to another issue that is posted on this forum.
As a temporary solution, I try to have my sweater page results in a bunch of products of a table. .
I have another table of warnings that are joined by the product ID
The table of warnings will have several elements with the same part number (different warning IDs)
Then, when I pull in products, get multiples of the same products
I tried a number of different methods to get this not not to shoot in multiples:
I tried SEPARATE just on products
I tried a subquery using SEPARATE the WHERE statement
SEPARATE does not work, and I read that it isn't exactly the best way to to do.
If not, how can I do?
Below is basically how I tried to do.
SELECT P.ID, HAZ. PID, HAZ.hazardID
FROM tblProducts P
LEFT OUTER JOIN tblHazard HAZ on P.ID is HAZ. NEST
WHERE (HAZ. PID IN (SELECT DISTINCT PID FROM tblHazard sHAZ))
> All that I really need to know isBob and Frank have children.
OK, so you may want to the result to be something like:
Children of the employee
Yes Bob
Frank Yes
Jim No.
Fix?
Assuming that it is a standard database, we would have 2 tables - used and the child. An inner join of employee for child returns only employees with children. An outer join of the used for child where the child value = Null returns employees without children. Using a UNION, we can combine the two to get the results above.
Now, what you want in your query?
Tags: Dreamweaver
Similar Questions
-
Select distinct slow on a single column
Oracle 10.2.0.4
Linux
I have two requests on the same table.
Select distinct month_id from ABC; --> Uses indexes not even if the index/Index_ffs flag is used. Takes 12 minutes to complete.
Select distinct cost_center from ABC; - > use indexes and runs much faster. Full within minutes.
There are differences in DISTINCT_VALUES and Clustering coefficient for two columns. I would like to know if month_id query can be made to run faster anyway.SQL> select Distinct month_id from abc; Execution Plan ---------------------------------------------------------- Plan hash value: 1358216387 ------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 22 | 66 | 144K (6)| 00:33:40 | | | | 1 | HASH UNIQUE | | 22 | 66 | 144K (6)| 00:33:40 | | | | 2 | PARTITION LIST ALL| | 36M| 104M| 139K (3)| 00:32:37 | 1 | 5 | | 3 | TABLE ACCESS FULL| abc | 36M| 104M| 139K (3)| 00:32:37 | 1 | 5 | ------------------------------------------------------------------------------------------------------- SQL> select distinct cost_center from abc; Execution Plan ---------------------------------------------------------- Plan hash value: 37945703 -------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop | -------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 8778 | 52668 | | 80860 (6)| 00:18:53 | | | | 1 | HASH UNIQUE | | 8778 | 52668 | 420M| 80860 (6)| 00:18:53 | | | | 2 | PARTITION LIST ALL| | 36M| 209M| | 5421 (2)| 00:01:16 | 1 | 5 | | 3 | INDEX FULL SCAN | abc_idx2 | 36M| 209M| | 5421 (2)| 00:01:16 | 1 | 5 | -------------------------------------------------------------------------------------------------------------------- SQL>
There is an index on the month_id column abc_idx5.
Let me know if you need more information.
Published by: HAP on September 30, 2009 10:22INDEX_NAME INDEX_TYPE BLEVEL LEAF_BLOCKS DISTINCT_KEYS CLUSTERING_FACTOR NUM_ROWS SAMPLE_SIZE abc_IDX2 NORMAL 2 53390 21543 3386600 34762540 3476254 abc_IDX5 NORMAL 2 32320 22 5279502 36667820 36667820
Published by: HAP on September 30, 2009 10:26I guess that month_id is optional and cost_center is mandatory:
SQL> create table t as select level v1, mod(level,10) v2, mod(level,100) v3, mod(level,1000) v4 from dual connect by level <= 100000; Tabel is aangemaakt. SQL> desc t Naam Null? Type ----------------------------------------- -------- ---------------------------- V1 NUMBER V2 NUMBER V3 NUMBER V4 NUMBER SQL> create index t4 on t (v4); Index is aangemaakt. SQL> analyze table t compute statistics; Tabel is geanalyseerd. SQL> select distinct v4 from t; Uitvoeringspan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=159 Card=1000 Bytes= 3000) 1 0 SORT (UNIQUE) (Cost=159 Card=1000 Bytes=3000) 2 1 TABLE ACCESS (FULL) OF 'T' (Cost=29 Card=100000 Bytes=30 0000) SQL> alter table t modify v4 not null; Tabel is gewijzigd. SQL> select distinct v4 from t; Uitvoeringspan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=152 Card=1000 Bytes= 3000) 1 0 SORT (UNIQUE) (Cost=152 Card=1000 Bytes=3000) 2 1 INDEX (FAST FULL SCAN) OF 'T4' (NON-UNIQUE) (Cost=22 Car d=100000 Bytes=300000)
Oracle is unable to use the index to determine if there are null values in the month_id column. I know three alternatives:
1. Add a clause not null to the query if you are not interested in null values
SQL> alter table t modify v4 null; Tabel is gewijzigd. SQL> select distinct v4 from t where v4 is not null; Uitvoeringspan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=152 Card=1000 Bytes= 3000) 1 0 SORT (UNIQUE) (Cost=152 Card=1000 Bytes=3000) 2 1 INDEX (FAST FULL SCAN) OF 'T4' (NON-UNIQUE) (Cost=22 Car d=100000 Bytes=300000)
2. use a union, but this query will take 12 minutes if all rows have a month_id
SQL> select distinct v4 from t where v4 is not null 2 union 3 select v4 from t where v4 is null and rownum = 1 4 ; Uitvoeringspan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=183 Card=1001 Bytes= 3003) 1 0 SORT (UNIQUE) (Cost=183 Card=1001 Bytes=3003) 2 1 UNION-ALL 3 2 INDEX (FAST FULL SCAN) OF 'T4' (NON-UNIQUE) (Cost=22 C ard=100000 Bytes=300000) 4 2 COUNT (STOPKEY) 5 4 TABLE ACCESS (FULL) OF 'T' (Cost=29 Card=1 Bytes=3)
3. create an index that contains a constant to the first position; This index includes all rows with null values
SQL> create index t4_2 on t ( 1, v4 ); Index is aangemaakt. SQL> select distinct v4 from t; Uitvoeringspan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=134 Card=1000 Bytes= 3000) 1 0 SORT (UNIQUE) (Cost=134 Card=1000 Bytes=3000) 2 1 INDEX (FAST FULL SCAN) OF 'T4_2' (NON-UNIQUE) (Cost=4 Ca rd=100000 Bytes=300000)
The fourt solution to change month_id not NULL :)
-
Hello
I use Microsoft SQL Server 2014 (SP1 - CU4) (KB3106660) Enterprise Edition (64-bit) on Windows NT 6.1(Build 7601: Service Pack 1) SELECT DISTINCT A.PI_LOOKUP_CATEGORY_ID,
REPLACE (REPLACE (UPPER (A.LOOKUP_CATEGORY_NAME), ' ', '_'), '-', '_') AS CATEGORY_TECH_NAME,
A.LOOKUP_CATEGORY_NAME,
A.LOOKUP_CATEGORY_DESCR,
COUNT (B.PI_LOOKUP_CATEGORY_ID) AS USAGE_COUNT
FROM [PI_LOOKUP_CATEGORY] A LEFT OUTER JOIN B [PI_INSIGHT_COLUMN] WE
A.PI_LOOKUP_CATEGORY_ID = B.PI_LOOKUP_CATEGORY_ID
A.PI_LOOKUP_CATEGORY_ID GROUP,
REPLACE (REPLACE (UPPER (A.LOOKUP_CATEGORY_NAME), ' ', '_'), '-', '_').
A.LOOKUP_CATEGORY_NAME,
A.LOOKUP_CATEGORY_DESCR
ORDER TO REPLACE (REPLACE (UPPER (A.LOOKUP_CATEGORY_NAME), ' ', '_'), '-', '_')above request is failed with error ' ORDER BY items must appear in the select list if SELECT DISTINCT is specified. " Microsoft SQL Server (SP1 - CU4) 2014 (KB3106660)
same query works fine with older versions of SQL servers like (2008R2, or 2012)
Please let me know the resolution of this problem...
Thank you
TouriaAsk here:
-
Explain plan for select distinct
I got 1 of the online test and there the question has been asked. I have already answered but curious to cross-check my response with your advice...
Question
Explain what information plan if the show room in SQL indicates that a separate select statement is made in the SQL.
The choices are:
Sort by a join
b sort by
c single fate
d sort aggregate
group e - sort by
My answer
I gave aggregates of SORT but it seems that his unique kind, because when I run explain plan then I see (unique) hash. Please guide
SEPARATE will identify unique rows. So in the given choice it would be KIND of UNIQUE. But oracle could go other plans as UNIQUE HASH or same INDEX FULL SCAN.
Look at the oracle does not SORT.
SQL> select distinct ename from emp; ENAME ------ SMITH BLAKE CLARK KING ADAMS TURNER ALLEN SCOTT JONES MARTIN WARD 11 rows selected. SQL> select * from table(dbms_xplan.display_cursor); PLAN_TABLE_OUTPUT --------------------------------------------------------------------------------- SQL_ID 6b32yqumjmp9b, child number 0 ------------------------------------- select distinct ename from emp Plan hash value: 984151148 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 3 (100)| | | 1 | HASH UNIQUE | | 11 | 66 | 3 (34)| 00:00:01 | | 2 | TABLE ACCESS FULL| EMP | 11 | 66 | 2 (0)| 00:00:01 | --------------------------------------------------------------------------- 14 rows selected.
Let me make an explicit ORDER BY for her to performa SORT.
SQL> select distinct ename from emp order by 1; ENAME ------ ADAMS ALLEN BLAKE CLARK JONES KING MARTIN SCOTT SMITH TURNER WARD 11 rows selected. SQL> select * from table(dbms_xplan.display_cursor); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------- SQL_ID f72vjx5rmm0z4, child number 0 ------------------------------------- select distinct ename from emp order by 1 Plan hash value: 725351111 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 4 (100)| | | 1 | SORT UNIQUE | | 11 | 66 | 3 (34)| 00:00:01 | | 2 | TABLE ACCESS FULL| EMP | 11 | 66 | 2 (0)| 00:00:01 | --------------------------------------------------------------------------- 14 rows selected. SQL>
Version - 10.2.0.5.0
-
Die column
'V_LIEFERSCHEIN_C '. "' LIEFERSCHEIN_NR ' as 'EPA '.
as separate essential den, soll aber ist in der Ausgabe displaying werden nicht.
ICH habe keine Adminrechte auf der data base und darf nur Aufenthaltsraume.man views und internal read!
Kann mir refer someone help?
SELECT distinct
NULL as GKZ
SUBSTR ("V_LIEFERSCHEIN_A". "" BESTELLZEICHEN»(, 1, 1) as "IF", "
SUBSTR ("V_LIEFERSCHEIN_A". "" BESTELLZEICHEN»(, 2) as "KUNDNUM", "
NULL as THEIR,
'V_LEISTUNGSORT '. "' ADRESS_HINWEIS ' like name1,
NULL as name2,
'V_LEISTUNGSORT '. "" STRAßE "as STRASSE.
'V_LEISTUNGSORT '. "" POSTLEITZAHL "like PLZ,.
'V_LEISTUNGSORT '. "" ORT "AS ORT.
NULL as TV,
value NULL as FAX,
'V_LEISTUNGSORT '. "" STRAßE "as ABSTRA.
'V_LEISTUNGSORT '. "" POSTLEITZAHL "as ABPLZ.
'V_LEISTUNGSORT '. "' ORTSTEIL_LEISTUNGSORT ' like ABANDON.
NULL as GRUVOL,
'V_LIEFERSCHEIN_A '. "' TATS_MENGE ' as Menge,.
to_CHAR ("V_LIEFERSCHEIN_A". "AUSFUEHRUNGSDATUM", 'dd.mm.yyyy') as TANGUY,.
'V_LIEFERSCHEIN_B '. "' TATS_MENGE ' as LAENGE.
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% EILZU '.
then 'J '.
on the other
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% EILZU '.
then 'J '.
another "n".
end
end up like "EILZU."
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% FEIERZU '.
then 'J '.
on the other
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% FEIERZU '.
then 'J '.
another "n".
end
end up like "FEIERZU."
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% SONDERZ '.
then 'J '.
on the other
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% TEST '.
then 'J '.
another "n".
end
end up like "SONDERZEIT."
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% LEEF '.
then 'J '.
on the other
case
"When' V_LIEFERSCHEIN_C '. "' TAETIGKEIT_KURZBEZ ' like '% LEEF '.
then 'J '.
another "n".
end
end up like "LEERFA."
case
When "V_LIEFERSCHEIN_B". "" TATS_MENGE "> 15
then "V_LIEFERSCHEIN_B". "" TATS_MENGE "-15
0 otherwise
end up like "LAENGE > 15.
'V_LIEFERSCHEIN_C '. "' LIEFERSCHEIN_NR ' as 'EPA '.
OF "V_LIEFERSCHEIN" "V_LIEFERSCHEIN_A"
"V_LEISTUNGSORT,"
"V_LIEFERSCHEIN" "V_LIEFERSCHEIN_B"
"V_LIEFERSCHEIN" "V_LIEFERSCHEIN_C".
WHERE ("V_LIEFERSCHEIN_A". "" LEISTUNGSORT_ID "="V_LEISTUNGSORT. " (' "LEISTUNGSORT_ID") and
("V_LIEFERSCHEIN_A". "" LIEFERSCHEIN_NR "="V_LIEFERSCHEIN_B. " (' "LIEFERSCHEIN_NR") and
("V_LIEFERSCHEIN_A". "" LIEFERSCHEIN_NR "="V_LIEFERSCHEIN_C. " (' "LIEFERSCHEIN_NR") and
(("V_LIEFERSCHEIN_A". ("' AUSFUEHRUNGSDATUM" > =: months) AND
("V_LIEFERSCHEIN_A". ("' AUSFUEHRUNGSDATUM" < =: stopdatum) AND
("V_LIEFERSCHEIN_A". ("" DEBITOR_NR "= 3532033) AND
("V_LIEFERSCHEIN_A". ("' STATUS ' in ("FAKT","FIBU")) AND
("V_LIEFERSCHEIN_A". ("' TAETIGKEIT_KURZBEZ ' like '% ABWAS') AND
("V_LIEFERSCHEIN_B". ((' ' TAETIGKEIT_KURZBEZ ' like '% SMART'))
Simply select what you want:
Select gkz
If
kundnum
their
, ...
de)
SELECT distinct
NULL as GKZ
SUBSTR ("V_LIEFERSCHEIN_A". "" BESTELLZEICHEN»(, 1, 1) as "IF", "
SUBSTR ("V_LIEFERSCHEIN_A". "" BESTELLZEICHEN»(, 2) as "KUNDNUM", "
NULL as THEIR,
'V_LEISTUNGSORT '. "' ADRESS_HINWEIS ' like name1,
NULL as name2,
'V_LEISTUNGSORT '. "" STRAßE "as STRASSE.
'V_LEISTUNGSORT '. "" POSTLEITZAHL "like PLZ,.
'V_LEISTUNGSORT '. "" ORT "AS ORT.
NULL as TV,
value NULL as FAX,
'V_LEISTUNGSORT '. "" STRAßE "as ABSTRA.
'V_LEISTUNGSORT '. "" POSTLEITZAHL "as ABPLZ.
'V_LEISTUNGSORT '. "' ORTSTEIL_LEISTUNGSORT ' like ABANDON.
NULL as GRUVOL,
'V_LIEFERSCHEIN_A '. "' TATS_MENGE ' as Menge,.
to_CHAR ("V_LIEFERSCHEIN_A". "AUSFUEHRUNGSDATUM", 'dd.mm.yyyy') as TANGUY,.
'V_LIEFERSCHEIN_B '. "' TATS_MENGE ' as LAENGE.
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% EILZU '.
then 'J '.
on the other
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% EILZU '.
then 'J '.
another "n".
end
end up like "EILZU."
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% FEIERZU '.
then 'J '.
on the other
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% FEIERZU '.
then 'J '.
another "n".
end
end up like "FEIERZU."
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% SONDERZ '.
then 'J '.
on the other
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% TEST '.
then 'J '.
another "n".
end
end up like "SONDERZEIT."
case
When "V_LIEFERSCHEIN_C". "' TAETIGKEIT_KURZBEZ ' like '% LEEF '.
then 'J '.
on the other
case
"When' V_LIEFERSCHEIN_C '. "' TAETIGKEIT_KURZBEZ ' like '% LEEF '.
then 'J '.
another "n".
end
end up like "LEERFA."
case
When "V_LIEFERSCHEIN_B". "" TATS_MENGE "> 15
then "V_LIEFERSCHEIN_B". "" TATS_MENGE "-15
0 otherwise
end up like "LAENGE > 15.
'V_LIEFERSCHEIN_C '. "' LIEFERSCHEIN_NR ' as 'EPA '.
OF "V_LIEFERSCHEIN" "V_LIEFERSCHEIN_A"
"V_LEISTUNGSORT,"
"V_LIEFERSCHEIN" "V_LIEFERSCHEIN_B"
"V_LIEFERSCHEIN" "V_LIEFERSCHEIN_C".
WHERE ("V_LIEFERSCHEIN_A". "" LEISTUNGSORT_ID "="V_LEISTUNGSORT. " (' "LEISTUNGSORT_ID") and
("V_LIEFERSCHEIN_A". "" LIEFERSCHEIN_NR "="V_LIEFERSCHEIN_B. " (' "LIEFERSCHEIN_NR") and
("V_LIEFERSCHEIN_A". "" LIEFERSCHEIN_NR "="V_LIEFERSCHEIN_C. " (' "LIEFERSCHEIN_NR") and
(("V_LIEFERSCHEIN_A". ("' AUSFUEHRUNGSDATUM" > =: months) AND
("V_LIEFERSCHEIN_A". "" AUSFUEHRUNGSDATUM ".<= :stopdatum="" )="">=>
("V_LIEFERSCHEIN_A". ("" DEBITOR_NR "= 3532033) AND
("V_LIEFERSCHEIN_A". ("' STATUS ' in ("FAKT","FIBU")) AND
("V_LIEFERSCHEIN_A". ("' TAETIGKEIT_KURZBEZ ' like '% ABWAS') AND
("V_LIEFERSCHEIN_B". ((' ' TAETIGKEIT_KURZBEZ ' like '% SMART'))
)
-
Hello!
Is it possible to force the optimizer to use a non-unique index for qurey below?
select distinct id from t1 union all select distinct id from t2;
I'm usung 11.2.0.3Thank you and best regards,
PavelSo declare them non-null. Unless you do this, you cannot use an index.
-
Hello
I have the following problem. A table with appox 650 000 rows and 200 columns queried to distinct values in a column (SN) of type VARCHAR2 (200 Bytes).
The query returns the 40 distinct values in 30 seconds. I would like to shoot this day here.
The original DBA had created a unique index on two columns (SN, DN). Column DN's NUMBER (10.0).
When I run the query with autotrace on I see that the index is not used and a full table scan.
I tried to create an index on just SN, i.e. being not used.
Any suggestions?
Thank you.natet wrote:
John,
The column definition for the two shows like 'Yes' nullable columns, but the data itself have no nulls for the column.You know that the data have no null values and now, I know as well, but does not know that the optimizer and may not know that without you say things as well.
Add a predicate to your query sn is not null, and it should start to use the index given that sn is the leading column of the index.
Please note should in the sentence that precedes, the opitimizer may still decide that a full analysis is the way to go, but if you query is of the form:
select distinct sn from table where sn is not null
My bet would be that it will use an index.
John
-
Select distinct cardno how ti implement in owb
Hello world
I'm quiet new to owb and I want to know how to use the separate in owb...
my query is
Select distinct Caron, brand_edesc
table tlog where
edesc = 'AAAA '.
and tmonth > = 200807 and tmonth < = 200809
so my question is
to find out where the clause I now use the filter operator, I want to know in owb which carrier we use to select distinct?
Thank you very muchYou can use Deduplicator operator.
Drag the Deduplicator operator and pass cardno, brand_edesc to it.See you soon
Katia -
Need help with select distinct in group by
RDBMS 10 g 2
I have tried what a separate select statement with an order by and having looked on the internet and try different examples, I was unsuccessful.
Here is the code work (not tri - I want to sort by pps.last_name but I can't seem to make it work).
select distinct pps.last_name || ', ' ||pps.first_name || ' ' ||pps.middle_initial || '.' d, emple_no r from cobr.vw_pps_payroll pps, projman pm where term_date is null and department = '0004400000' and pm.eid != pps.emple_no
Given that the family name is the leading role or your concatenated column 1, how about this:
select distinct pps.last_name || ', ' ||pps.first_name || ' ' ||pps.middle_initial || '.' d, emple_no r from cobr.vw_pps_payroll pps, projman pm where term_date is null and department = '0004400000' and pm.eid != pps.emple_no order by 1
-
Hi all
each claim_number can be 3 articlesDESC CLAIMS CLAIM_NUMBER NUMBER(10) VERSION NUMBER(2) STATUS NUMBER(1)
0/9/1
There must be at least 1 table
I want to go get CLAIM_NUMBER that contain the value only one StateSelect CLAIM_NUMBER ,STATUS from claims order by CLAIM_NUMBER,STATUS ------------------------------------------- CLAIM_NUMBER STATUS ------------------------------------------- 6971700 1 6971700 1 6971700 0 8624300 9 10071200 1 10453800 0 10453800 0
as CLAIM_NUMBER = 10453800 (that contain only 0)
10071200 (which contain only 1)
8624300 (containing only 9)
I started a query like this
the problem is that I want to add to the condition, status value as 9 or 0select CLAIM_NUMBER from CLAIMS group by CLAIM_NUMBER having count(distinct(status)) < 2
How do I do it?
Thanks in advance
Naamaselect CLAIM_NUMBER from CLAIMS group by CLAIM_NUMBER having count(distinct(status)) = 1 and avg(status) = your-status
-
How to select distinct on two fields?
REC_ID STREET TYPE XY
STREET1 ID00009BBB TYPE_A 121.0261138 14.39273926
STREET1 ID00009BBC TYPE_A 121.0261369 14.39196578
STREET1 ID0001592C TYPE_B 121.0595288 14.54142606
STREET.2 ID0001592D TYPE_B 121.0596636 14.54135598
STREET.2 ID0001592E TYPE_A 121.0604688 14.54128005
STREET.2 ID0001592F TYPE_A 121.0610727 14.54119853
ID00015930 STREET.2 TYPE_B 121.0616964 14.54109215
STREET3 ID0001E500 TYPE_A 120.8653957 14.86388395
STREET3 ID0001E501 TYPE_A 120.8656432 14.86390451
I need to separate Street exit and type whatever value rec_id, x and y...
Required output
STREET1 ID00009BBB TYPE_A 121.0261138 14.39273926
STREET1 ID0001592C TYPE_B 121.0595288 14.54142606
STREET.2 ID0001592D TYPE_B 121.0596636 14.54135598
STREET.2 ID0001592E TYPE_A 121.0604688 14.54128005
STREET3 ID0001E500 TYPE_A 120.8653957 14.86388395Hello
Looks like you want exactly a complete line, exactly as it is on your table, for all the distinct combinations of street and type.
It is unclear who the rank that is, when there is a choice.WITH got_r_num AS ( SELECT rec_id, street, type, x, y , ROW_NUMBER () OVER ( PARTITION BY street , type ORDER BY x , y ) AS r_num FROM my_table ) SELECT rec_id, street, type, x, y FROM got_r_num WHERE r_num = 1 ;
The above query takes over the line with the lowest x, or, in the case of a tie, the lowest there.
If this isn't what you want, then change the analytical ORDER BY clause. -
SELECT DISTINCT to Excel datasource
I am trying to import data from an Excel worksheet in MS SQL 2005. I had planned on just querying the worksheet, and then loop through the lines and inserting them one by one.
I can get it works well, however, there are some I'm trying to exclude duplicate entries. However, when I put in the SEPARATE, I get only back 75 recordings of the leaf, which has almost 4000. If I remove the separate, I get all the lines, but I would like to remove duplicates. I'm doing something wrong?
Here is the code:
< cfquery name = "getrecords" datasource = "spayusa" dbtype = "odbc" >
Select the separate AGENCY
PROGRAM_ADDRESS
PROGRAM_city
PROGRAM_state
PROGRAM_zip
PROGRAM_area_code
PROGRAM_phone
from the data
< / cfquery >
name addressline1, addressline2, city state zip phone zipplusfour
< cfoutput query = "getrecords" >
< cfquery name = "insertrecords" datasource = "spayflorida" >
insert into spayflorida_spayneuterprogram)
name
addressline1
City
State
zip
phone
)
values)
< cfqueryparam cfsqltype = "cf_sql_varchar" list = "" value = "#getrecords.ORGANIZATION #" >
, < cfqueryparam cfsqltype = "cf_sql_varchar" list = "" value = "#getrecords. PROGRAM_ADDRESS #">"
, < cfqueryparam cfsqltype = "cf_sql_varchar" list = "" value = "#getrecords. PROGRAM_city #">"
, < cfqueryparam cfsqltype = "cf_sql_varchar" list = "" value = "#getrecords. PROGRAM_state #">"
, < cfqueryparam cfsqltype = "cf_sql_varchar" list = "" value = "#getrecords. PROGRAM_zip #">"
, < cfqueryparam cfsqltype = "cf_sql_varchar" list = "none" value = "(#getrecords.)" PROGRAM_area_code #) #getrecords. PROGRAM_phone #">"
)
< / cfquery >
< / cfoutput >
> when I put in the SEPARATE, I get only back 75 sheet records,.
> who has almost 4000SEPARATE must return the unique combinations of fields that you have listed. If the 'distinct' query returns only 75 records it suggests there are only 75 unique combinations
ORGANIZATION
PROGRAM_ADDRESS
PROGRAM_city
PROGRAM_state
PROGRAM_zip
PROGRAM_area_code
PROGRAM_phone -
using the button to select distinct values
I would like to have a button where a user can choose one of four options: 6, 12, 18, 24. I updated the properties of force and I changed the labels so that it looks only four options are available but it always allows me to choose between 6 to 24 in 1 increments. I used an indicator to see what data are produced by the control and it shows also from 6 to 24 with increments of 1. Am just using the wrong control?
You can use text labels. Right click on the Select button. Right click again and create the visible text display. You can then right-click on the display of text labels and select "edit items". Add as many items as you want and to assign a digital specific to each label, uncheck the box for sequential values.
-
Select * FROM PREMISE_INSERT has
WHERE EXISTS (SELECT MIN(B.SERV ||) (Group B.PREM) OF B PREMISE_INSERT of b.prem)
ORDER BY A.PREM;
I have this query I thought should return one row for each number of PREM, but refers everything. I want to retrieve a single record for each PREM having the lowest value SERV. Any ideas?
PREM SERV A 1316633 2000, 5555 MYSTREET AV JOHN SMITH 585263 44 4400 N 4400 Q A 1316633 2001, 5555 MYSTREET AV JOHN SMITH 585263 N 44 Q Hello
Thanks for posting the CREATE TABLE statement. Now I'm waiting just to INSERT and instructions the correct results, you want the given data.
If only 3 columns in the table play no role in this issue, then do not include the other columns in the CREATE TABLE and INSERT statements.
The query in response No. 5 included
ROW_NUMBER() over (PARTITION BY prem, serv ORDER BY prem, serv) rn
This is obviously a mistake. Ever, it makes sense to use the same term in the PARTITION BY and ORDER BY of the same analytical function clauses.
Try changing it to:
ROW_NUMBER () (PARTITION BY prem - AND NO serv
ORDER BY serv - and NOT prem
), Rn
-
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
I'm trying to return different data. If (Field1, Field2) = (Field2, Field1) so I want to only return one of the lines that iscreate table test_table (field1 varchar2(10),field2 varchar2(10)); insert into test_table values ('value1','value2'); insert into test_table values ('value2','value1'); insert into test_table values ('value3','value4'); insert into test_table values ('value4','value3'); select * from test_table; field1 field2 value1 value2 value2 value1 value3 value4 value4 value3
orfield1 field2 value1 value2 value3 value4
or any other Variant.field1 field2 value2 value1 value4 value3
Due to the restriction/nature of the system, that ideally would be in a where clause clause...
Any ideas how this can be achieved?select * from test_table where ...
Thank you.LSU says:
Due to the restriction/nature of the system, that ideally would be in a where clause clause...
Then?
SQL select * 2 from test_table t1 3 where not exists (select '' 4 from test_table t2 5 where t2.field1 = least(t1.field1,t1.field2) 6 and t2.field2 = greatest(t1.field1,t1.field2) 7* and t2.rowid != t1.rowid) SQL> / More... FIELD1 FIELD2 ---------- ---------- value3 value4 value1 value2 2 rijen zijn geselecteerd.
Published by: Toon Koppelaars December 7, 2011 10:48
Maybe you are looking for
-
How can I download Firefox?
It stays on the screen a moment that Firefox will launch as soon as installation is complete. Windows PC 8
-
downturn or remove preloaded music without formatting
After downloading the new update, it takes me about 5 minutes (instead of instantly) to access my folder of music in MSC mode. And the 'your refreshing media' takes more time. I would also like to know how to delete the pre-recorded music without for
-
How to fix error 0 x 00000035 no irp stack locations more
My computer started acting a little slower so I decided to restart it, and when he went to the symbol for windows at startup normal music/noise got all weird sounding and showed me the error blue screen of 0 x 00000035 No. PRI more stack locations. I
-
Windows 7 Home basic product key lost
I had Windows 7 Home basic I formatted my PC... during reinstallaton... I know I lost the product key...I have CD of Home base... that have the number of COA barcode... I did this CD in my local retail IT store... Please tell me how I can retrieve pr
-
error: 'QGeoPositionInfo' does not designate a type
Based on https://developer.blackberry.com/cascades/documentation/device_platform/location/index.html, I tried to build the following codes: /* * GPSinfo.h * * Created on: Sep 18, 2012 * Author: CNTEXIE */ // To start receiving position information, /