sql server - SQL Query that returns all records when the where clause subquery has invalid column name...? -
this question has answer here:
- misnamed field in subquery leads join 4 answers
so there's query in legacy app never worked, because subquery wrong. sql query below:
select companyname companies companyid = (select compnyid users userid = 123) as can see, in subquery, companyid missing , spelled wrong. yet, when run entire query, returns records in companies. when run subquery, says "invalid column name 'compnyid'." why happen? why doesn't query error? kind of confusing me, i'm curious why query runs. assume it's quirk subqueries?
thanks!
i wonder if real query. description suggests there column in companies called compnyid.
table aliases idea. when using subqueries, should mandatory. think writing:
select c.companyname companies c c.companyid = (select u.compnyid users u u.userid = 123); but, because u.compnyid not exist, interpreted as:
select c.companyname companies c c.companyid = (select c.compnyid users u u.userid = 123) this return columns 2 values same.
Comments
Post a Comment