views:

42

answers:

3

the link is http://www.sqlcommands.net/sql+join/

i would like to know if it would work if it were

SELECT Weather.City
FROM Weather
WHERE Weather.City = State.City

meaning select all those cities "from weather" which belong in the state table

will the above work if not then why?

+1  A: 

Your query won't work because the table State does not appear in the FROM clause so you can't reference its columns.

This would work though:

SELECT Weather.City
FROM Weather
JOIN State
ON Weather.City = State.City
Mark Byers
other answers are help ful tooooo thanku
+2  A: 

No because to use State.City, the table State needs to be somewhere in the FROM list.

The alternate to the example you provided would be:

SELECT Weather.City
FROM Weather
INNER JOIN State
ON Weather.City = State.City
Justin Niessner
A: 

or, as an alternative (using yr english sentence as a guide):

SELECT City                -- select all those cities
FROM Weather               -- "from weather"
Where City In              -- which 
  (Select City From State) -- belong in the state table
Charles Bretana