|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Find common rows
Hy, I have a query which return the following result. That is a list of rows with 2 columns. Some numbers are common in certain rows. I need to combine all common numbers in 1 row.
If I have the following rows: ID | DUP_ID "30007";"30008"; "30005";"30007"; "30006";"30011"; "30004";"30006"; "30001";"30006"; "30012";"30013"; my final result should be: 30007; 30008; 30005 30006; 30011; 30004; 30001 30012; 30013 How to achieve this. thanks in advance gul |
|
#2
|
||||
|
||||
|
You can do this by using two queries:
select distinct ID from table --gets the first ID's select distinct DUP_ID from table where DUP_ID not in (select distinct ID from table) --gets those ID's that weren't in the first batch Or you can declare a table variable (with one column), read all of the ID's and DUP_ID's into it, and just select the distinct ID's |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Find common rows |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|