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
 joins

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2010-08-20 : 11:19:27
Im going to have two tables on any given day table one could have more rows then table two but the next day it could switch but I need to make sure all the rows from both tables are always shown any suggestions?

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-08-20 : 11:21:41
What do you mean "always shown"?? Can you elaborate.
Go to Top of Page

gavakie
Posting Yak Master

221 Posts

Posted - 2010-08-20 : 11:28:26
The all the data from both tables is always shown. Im thinking if I did a left join on table 1 when it has more its fine, but the next day if there more in table 2 id lose those columns from table 2.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-20 : 12:05:43
then do a full outer join between tables and use COALESCE(t1.field,t2.field) to get field value.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-08-20 : 12:10:00
Another alternative:
SELECT * FROM TableOne
UNION
SELECT * FROM TableTwo
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-20 : 12:14:33
quote:
Originally posted by Lamprey

Another alternative:
SELECT * FROM TableOne
UNION
SELECT * FROM TableTwo



depends
what if there are some different columns and we have to show all the columns from both table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -