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
 General SQL Server Forums
 New to SQL Server Programming
 Find Common value in column for 30 tables

Author  Topic 

JeffT
Posting Yak Master

111 Posts

Posted - 2006-03-21 : 10:06:15
Hi,

I am trying to query for a common value in a column called "file_auth_nbr" in 30 different tables. I was going to try something like this (see below) but wasn't sure if this was the most efficient, fastest, or correct, way to get what I'm looking for:

Select distinct a.file_auth_nbr from table1 as a
join table2 as b
on a.file_auth_nbr = b.file_auth_nbr
join table3 as c
on a.file_auth_nbr = c.file_auth_nbr
join table4 as d
on a.file_auth_nbr = d.file_auth_nbr
join table5 as e
on a.file_auth_nbr = e.file_auth_nbr
......etc., etc.

Any suggestions would be much appreciated,
Jeff

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-03-21 : 10:54:55
This could have a few problems if file_auth_nbr can occur multiple times in a table. You will end up with somthing similar to a cross join with a million bizillion rows in SQL Server's internal work tables.

You should try to do it with a union query.



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -