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 2005 Forums
 Transact-SQL (2005)
 Query from 3 tables

Author  Topic 

Sep410
Posting Yak Master

117 Posts

Posted - 2008-06-05 : 16:05:09
Hi,
I know it is simple query but I am confused.
I need to make a query from 3 tables in the same database. There are no relations between these tables.
Here is result I need.
KE LE JE
15 775.5 398
18 192.23 399


Please help me.


Sep

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-05 : 16:18:49
If there is no relation between the three tables, then you can't join them together.

You could union them together though.

SELECT A FROM Table1
UNOIN ALL
SELECT B FROM Table2
UNION ALL
SELECT C FROM Table3

I suppose you could pivot the data by using the above as a derived table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

Sep410
Posting Yak Master

117 Posts

Posted - 2008-06-05 : 16:25:06
Thank you for reply but I need to have
KE LE JE
15 775.5 398
18 192.23 399
Union All will return :
Ke
15
18
775.5
192.23
398
399
It is not what I need.


Please help me.


Sep
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-05 : 16:29:56
So you need to pivot it as mentioned in my first reply. Check out PIVOT in SQL Server Books Online. I don't have time to come up with a solution for you right now, so I provided the keywords you'll need.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

Sep410
Posting Yak Master

117 Posts

Posted - 2008-06-05 : 18:30:39
Ok,
Thanks

Sep
Go to Top of Page
   

- Advertisement -