Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

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

Starting Member

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.

Flowing Fount of Yak Knowledge

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

Flowing Fount of Yak Knowledge

8781 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

Starting Member

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  
 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.02 seconds. Powered By: Snitz Forums 2000