sql server - SQL Query that returns all records when the where clause subquery has invalid column name...? -


this question has answer here:

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

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -