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
 Querying two tables with select statement

Author  Topic 

Prosercunus
Starting Member

22 Posts

Posted - 2012-10-09 : 05:56:15
I have two tables. One called "Prof" and one called "Dept"

The Prof table has the columns "pname" (Professor Name) and "dname" (Department Name)

The Dept table has the columns "dname" (Department Name) and "numphds" (Number of PhD's)

Of course this causes me Ambiguous column name 'dname'. which I understand because it shares the same named column "dname"

How do I properly write the select statement to find names of professors who work in departments that have fewer than 50 PhD students.

I know it is something to do with assignments, but I am confused. Thanks.

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2012-10-09 : 06:01:07
Specify with table name Prof.dname / Dept.dname

Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-10-09 : 06:05:39
select p.pname, d.numphds
from Prof as p
join Dept as d on d.dname = p.dname and d.numphds < 50


Too old to Rock'n'Roll too young to die.
Go to Top of Page

Prosercunus
Starting Member

22 Posts

Posted - 2012-10-09 : 06:08:16
You guys are awesome. Thank you.
Go to Top of Page
   

- Advertisement -