dbTalk Databases Forums  

Selct DISTINCT

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Selct DISTINCT in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #21  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: Selct DISTINCT - 01-29-2008 , 03:38 PM






trpost (AT) gmail (DOT) com schrieb:

Quote:
So the problem I have is that there is some duplicate data in TABLE1
and TABLE2, but TABLE1 data always has more data available then in
TABLE2, so that is how I know if there is a duplicate to take the
first row.
You seem to miss Frank's point - there is no FIRST row in the relational
table (or in result set returned without order by clause). Either you
introduce ordering criteria and then utilize analytical functions to
eliminate *duplicates* or you take the approach - any one of them is as
good as another and remove all *duplicates* except a random one,
utilizing method you was shown by David.

Best regards

Maxim


Reply With Quote
  #22  
Old   
David Portas
 
Posts: n/a

Default Re: Selct DISTINCT - 01-29-2008 , 04:43 PM






On 29 Jan, 20:29, trp... (AT) gmail (DOT) com wrote:
Quote:
Let me expand a little on what I am actually doing, I provided a small
example in the original post as I thought there might be a simple way
to select the first distinct row based on one column.

Without specifics, here is how my query is structured:

SELECT DISTINCT(ID), NAME, SSN FROM
(

* * *SELECT DISTINCT(ID), NAME, SSN FROM TABLE1

* * *UNION ALL

* * *SELECT DISTINCT(ID), NAME, SSN FROM TABLE2

)

So the problem I have is that there is some duplicate data in TABLE1
and TABLE2, but TABLE1 data always has more data available then in
TABLE2, so that is how I know if there is a duplicate to take the
first row.
Maybe this is what you want:

SELECT id, name, ssn FROM Table1
UNION
SELECT id, name, ssn FROM Table2
WHERE NOT EXISTS
(SELECT id FROM Table1 WHERE id = Table2.id);

--
David Portas


Reply With Quote
  #23  
Old   
David Portas
 
Posts: n/a

Default Re: Selct DISTINCT - 01-29-2008 , 04:43 PM



On 29 Jan, 20:29, trp... (AT) gmail (DOT) com wrote:
Quote:
Let me expand a little on what I am actually doing, I provided a small
example in the original post as I thought there might be a simple way
to select the first distinct row based on one column.

Without specifics, here is how my query is structured:

SELECT DISTINCT(ID), NAME, SSN FROM
(

* * *SELECT DISTINCT(ID), NAME, SSN FROM TABLE1

* * *UNION ALL

* * *SELECT DISTINCT(ID), NAME, SSN FROM TABLE2

)

So the problem I have is that there is some duplicate data in TABLE1
and TABLE2, but TABLE1 data always has more data available then in
TABLE2, so that is how I know if there is a duplicate to take the
first row.
Maybe this is what you want:

SELECT id, name, ssn FROM Table1
UNION
SELECT id, name, ssn FROM Table2
WHERE NOT EXISTS
(SELECT id FROM Table1 WHERE id = Table2.id);

--
David Portas


Reply With Quote
  #24  
Old   
David Portas
 
Posts: n/a

Default Re: Selct DISTINCT - 01-29-2008 , 04:43 PM



On 29 Jan, 20:29, trp... (AT) gmail (DOT) com wrote:
Quote:
Let me expand a little on what I am actually doing, I provided a small
example in the original post as I thought there might be a simple way
to select the first distinct row based on one column.

Without specifics, here is how my query is structured:

SELECT DISTINCT(ID), NAME, SSN FROM
(

* * *SELECT DISTINCT(ID), NAME, SSN FROM TABLE1

* * *UNION ALL

* * *SELECT DISTINCT(ID), NAME, SSN FROM TABLE2

)

So the problem I have is that there is some duplicate data in TABLE1
and TABLE2, but TABLE1 data always has more data available then in
TABLE2, so that is how I know if there is a duplicate to take the
first row.
Maybe this is what you want:

SELECT id, name, ssn FROM Table1
UNION
SELECT id, name, ssn FROM Table2
WHERE NOT EXISTS
(SELECT id FROM Table1 WHERE id = Table2.id);

--
David Portas


Reply With Quote
  #25  
Old   
David Portas
 
Posts: n/a

Default Re: Selct DISTINCT - 01-29-2008 , 04:43 PM



On 29 Jan, 20:29, trp... (AT) gmail (DOT) com wrote:
Quote:
Let me expand a little on what I am actually doing, I provided a small
example in the original post as I thought there might be a simple way
to select the first distinct row based on one column.

Without specifics, here is how my query is structured:

SELECT DISTINCT(ID), NAME, SSN FROM
(

* * *SELECT DISTINCT(ID), NAME, SSN FROM TABLE1

* * *UNION ALL

* * *SELECT DISTINCT(ID), NAME, SSN FROM TABLE2

)

So the problem I have is that there is some duplicate data in TABLE1
and TABLE2, but TABLE1 data always has more data available then in
TABLE2, so that is how I know if there is a duplicate to take the
first row.
Maybe this is what you want:

SELECT id, name, ssn FROM Table1
UNION
SELECT id, name, ssn FROM Table2
WHERE NOT EXISTS
(SELECT id FROM Table1 WHERE id = Table2.id);

--
David Portas


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.