Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting distinct.

Status
Not open for further replies.

19giugno

Programmer
Jan 30, 2003
7
0
0
IT
Hi all, I know that is a stupid question, but i'm stupid with SQl.

I have 4 tables, with the same fields, with multiple rows (say the same record repeated in each table and possibly being on different tables). I need to extract all the records ONCE... joining the tables, maybe, don't know...

Anyone can help me?

Thanks.
 
SELECT DISTINCT *
FROM Table1, Table2, Table3, Table4

Assuming the records in the different tables are exactly identical, this should work.
"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
I am testing it now but i'm not sure it will work, cause i forgot to specify that the records are not exactly identical, but only one field is!

Say, 4 fields: ID, Name, LastName, EmailAddress

I've got many records with the same email address, I need to extract it once!

hope someone can help me...
 

You don't NEED a JOIN query. You need a UNION query.

Select ID, Name, LastName, EmailAddress
From table1
UNION
Select ID, Name, LastName, EmailAddress
From table4
UNION
Select ID, Name, LastName, EmailAddress
From table4
UNION
Select ID, Name, LastName, EmailAddress
From table4

Which RDMS are you using? Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top