Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select from Multiple Tables with Distinct Clause

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-08-09 : 08:22:07
John writes "I have an instance where I have 4 tables that all contain the same field. I want to build a sql statement that does not return duplicates from all the tables for 1 field.

Example: Select distinct assignee_email from PTRDOC, PTRHW, PTRSW, PTRSYS

Since the field is in all 4 tables it returns errors saying it the field can be in multiple tables. I am thinking I am going to have to make use of the join statement but I am not sure.

Thanks,
John"

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-08-09 : 08:46:01
I'm not sure what you're asking for.
Perhaps this?

SELECT assignee_email FROM PTRDOC
UNION
SELECT assignee_email FROM PTRHW
UNION
SELECT assignee_email FROM PTRSW
UNION
SELECT assignee_email FROM PTRSYS


Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-08-09 : 08:46:48

select assignee_email from PTRDOC
union
select assignee_email from PTRHW
union
select assignee_email from PTRSW
union
select assignee_email from PTRSYS

 
Now, I am afraid to ask why this query must exists. If assignee_email is a fk referencing some 5th table, you should be able to simple select from that table. Apparently, it's not, meaning you may have some design issues.

Jay White
{0}
Go to Top of Page
   

- Advertisement -