September 26, 2007 at 5:18 am
Hi All
I have a simple query
Select CustomerName from Customers
WHERE CustomerState IN (SELECT State FROM Addresses).
The catch is there is no "State" column in Addresses table, but there is a column called "State" in the Customers table. :w00t:
Any ideas ?
"Keep Trying"
September 26, 2007 at 5:57 am
if you don't explicitly say tablename.columnname, the engine does it's best to resolve the columns automatically, since there IS a state column in one of the two tables involved int his query,it uses Customer.State. this an example of unintended consequences of that feature.
if both tables had state in it, that's where you get the error from the compiler stating "Ambiguous column name 'state'"
Lowell
September 26, 2007 at 12:06 pm
it is a recommended practice that when you use subqueries you prefix all column names with a table alias!
* Noel
September 26, 2007 at 11:19 pm
Hi
Lowell
Thanks for explaining the thing to me..
Noel
I know its a good practice to prefix table names to columns.
I was just curious thats all. Thanks for your response.
"Keep Trying"
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply