View Single Post

   
  #2 (permalink)  
Old 02-28-2008, 07:32 PM
John Gilson
 
Posts: n/a
Default Re: Join Three tables?

"MEM" <mmaxsom@citlink.net> wrote in message news:9403d191.0310271531.75aa7bf4@posting.google.c om...
> hello,
>
> I'm need some help with some sql to return some data...obviously
>
> I have 3 tables. tblMgr, tblSup, and tblRep. I'd like to get all the
> names of the reps that are assigned to a particular manager.
>
> Here is a simplified exmaple of table setup:
>
> tblRep
> -------
> repid repname supid
> ----------------------
> 1 joe 500
> 2 ann 501
>
>
> tblSup
> -------
> supid supname mgrid
> ----------------------
> 500 bill 1000
> 502 tom 1001
>
>
> tblMgr
> -------
> mgrid mgrname
> ---------------
> 1000 andy
> 1001 roger
>
> Thanks.


CREATE VIEW RepsManagers (repid, repname, mgrid, mgrname)
AS
SELECT R.repid, R.repname, M.mgrid, M.mgrname
FROM tblRep AS R
INNER JOIN
tblSup AS S
ON R.supid = S.supid
INNER JOIN
tblMgr AS M
ON S.mgrid = M.mgrid

-- For example
SELECT *
FROM RepsManagers
WHERE mgrname = 'andy'

Regards,
jag


Reply With Quote