SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Querying two tables with select statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Prosercunus
Starting Member

USA
22 Posts

Posted - 10/09/2012 :  05:56:15  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
1007 Posts

Posted - 10/09/2012 :  06:01:07  Show Profile  Visit senthil_nagore's Homepage  Send senthil_nagore a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8766 Posts

Posted - 10/09/2012 :  06:05:39  Show Profile  Visit webfred's Homepage  Reply with Quote
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

USA
22 Posts

Posted - 10/09/2012 :  06:08:16  Show Profile  Reply with Quote
You guys are awesome. Thank you.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000