If you run a SELECT query that references a non-existing column, SQL Server raises an error Invalid column name as we would expect. However, if the SELECT appears in a sub-query, SQL Server doesn't raise any error
In the following example, let's say that the Northwind's Customers table doesn't have any Citi field (note the mispelled name). The following query raises an error:
SELECT Citi FROM Customers
Error: Invalid column name 'Citi'.
However, the following query doesn't raise any error, and returns records:
-- assume that the Region table doesn't contain a City field
SELECT * FROM Customers WHERE City IN (SELECT City FROM Region)
The problem seems to arise when the field appears in the main table, but not in the table mentioned in the subquery
Taking into consideration the above mentioned scenario ,it is good to be aware while using subqueries
|
No responses found. Be the first to respond and make money from revenue sharing program.
|