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
 Query to join three tables

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2012-08-31 : 10:36:52
Hi,

I have 3 tables with data;

Table 1

Fruit Quantity Price
Banana 20 £2
Apple 18 £1
Mango 15 £1


Table 2

Fruit Quantity Price
Pears 22 £2
Peeches 11 £1
Oranges 9 £1

Table 3

Fruit Quantity Price
Grapes 22 £2
cucumber 11 £1


I want my query to join all these tables so that I can have;


Output Results:

Fruit Quantity Price
Banana 20 £2
Apple 18 £1
Mango 15 £1
Pears 22 £2
Peeches 11 £1
Oranges 9 £1
Grapes 22 £2
cucumber 11 £1

Many thanks

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-08-31 : 10:59:48
select * from Table1
union all
select * from Table2
union all
select * from Table3


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2012-08-31 : 11:14:10
Thank you
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-31 : 11:17:11
can same fruit exists in multiple tables with different quantity? if thats case how should output be?

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

Go to Top of Page
   

- Advertisement -