SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with selecting and displaying specific dat
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

iNko
Starting Member

Lithuania
19 Posts

Posted - 12/03/2012 :  11:35:06  Show Profile  Reply with Quote
Hey, i have 3 tables and i want to fetch specific data from those tables. Iv been using this code:

SELECT Table1.sukurimo_data, Table2.issiuntimo_data, Table3.issiuntimo_data
FROM Table1, Table2, Table3
WHERE Table1.table_id= Table2.table_id
OR Table1.table_id= Table3.table_id


It currenrly displays data like this:


How do i make it so it would only be 2 columns, and it would fit data from both Table2 and Table3 into 2nd column?

Note, all 3 tables have the same 'id' key and all of them are set to primary

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 12/03/2012 :  11:38:57  Show Profile  Reply with Quote

SELECT Table1.sukurimo_data, Table2.issiuntimo_data,1 AS Ord
FROM Table1
INNER JOIN Table2
ON Table1.table_id= Table2.table_id

UNION ALL

SELECT Table1.sukurimo_data, Table3.issiuntimo_data,2 AS Ord
FROM Table1
INNER JOIN Table3
ON Table1.table_id= Table3.table_id
ORDER BY Table1.sukurimo_data,Ord


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

Go to Top of Page

iNko
Starting Member

Lithuania
19 Posts

Posted - 12/03/2012 :  12:58:35  Show Profile  Reply with Quote
Thank you so much, it finally works how i want to.. :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 12/04/2012 :  01:06:52  Show Profile  Reply with Quote
welcome

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000