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 three tables

Author  Topic 

Djave
Starting Member

4 Posts

Posted - 2008-07-10 : 11:01:08
Hi all,
i have three tables:
table 1 has two colomns: name and id
table 2 has two columns: countrycode and id(id in this table is the forgin key from table one)
table 3 has two columns: countryname and countrycode(countrycode is the forggin key from table two)

now i have to make a query to select the name from table one and the countryname that belongs to that name from table three .
can anyone help me to make this query???

Thanx.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-07-10 : 11:03:09
This is a pretty easy homework assignment. Give it a shot first and then post it here with any troubles or questions you have about it.

Jim
Go to Top of Page

Djave
Starting Member

4 Posts

Posted - 2008-07-10 : 11:06:30
Hi Jim , i m trying this for hours bud i did'nt get the right result.
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-07-10 : 11:08:53
Post what you tried

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

Djave
Starting Member

4 Posts

Posted - 2008-07-10 : 11:17:55
SELECT DEBFACT4DE.OPDCNR id ,ADRPF.ADLNDK as countrycode, LANFP.LALAND as countryName FROM DEBFACT4DE JOIN ADRPF
ON DEBFACT4DE.OPDCNR=ADRPF.ADNUMM
ON ADRPF.ANUMM=LANFP.LAKODE "

DEBFACT4DE IS TABLE ONE, ADRFP IS TABLE TWO, LANFP IS TABLE 3
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-07-10 : 11:24:52
SELECT
DEBFACT4DE.OPDCNR as id ,
ADRPF.ADLNDK as countrycode,
LANFP.LALAND as countryName
FROM DEBFACT4DE
LEFT JOIN ADRPF ON DEBFACT4DE.OPDCNR = ADRPF.ADNUMM
LEFT JOIN LANFP ON ADRPF.ANUMM=LANFP.LAKODE


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

Djave
Starting Member

4 Posts

Posted - 2008-07-10 : 11:36:46
thank you i will try it :)
Go to Top of Page
   

- Advertisement -