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
 Select from multiple tables

Author  Topic 

cutepraba
Yak Posting Veteran

53 Posts

Posted - 2007-12-18 : 03:29:56
I have four tables. now i need to select the rows from all the four tables.

TABLE1: -Job
jobno
mtid
prid
mtpath
prpath

TABLE2: - livestaff this id will be store in Job
staffid
staffname
teamid
active


TABLE3: -masterstaff
mstaffid
staffname
teamid
active


TABLE4: -staffrel
masterstaffid
livestaffid

Now i need to select * from job and staffname from masterstaff and teamid from livestaff.

Please help

____________
Praba

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-18 : 03:33:42
Join tables with key columns and select required columns from respective tables

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-18 : 04:14:19
something like:-
SELECT j.*,m.staffname,l.teamid
FROM Job j
INNER JOIN livestaff l
ON l.staffid=j.{corresponding id column}
INNER JOIN staffrel s
ON s.livestaffid=l.staffid
INNER JOIN masterstaff m
ON m.mstaffid=s.masterstaffid


learn more on joins from here:-

[url]http://msdn2.microsoft.com/en-us/library/ms190014.aspx[/url]
Go to Top of Page
   

- Advertisement -