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
 Problem with selecting and displaying specific dat

Author  Topic 

iNko
Starting Member

19 Posts

Posted - 2012-12-03 : 11:35:06
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

52326 Posts

Posted - 2012-12-03 : 11:38:57
[code]
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
[/code]

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

Go to Top of Page

iNko
Starting Member

19 Posts

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-04 : 01:06:52
welcome

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

Go to Top of Page
   

- Advertisement -