select salary from dbo.Employee where 1==1 . -- What will this query return?
Loading
select salary from dbo.Employee where 1==1 . -- What will this query return?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Dec 28, 2024, 4:36 PM
Hello Sourabh,
First of all == will not work,
In standard SQL, the equality operator is
=(not==). The query you wrote might not execute if the SQL dialect you're using does not support==for equality checks. The correct syntax would be:The
WHERE 1 = 1condition always evaluates toTRUE, meaning it applies no filtering to the data.As a result, every row in the table satisfies the condition and is included in the result.
Sourabh DhimanPosted Dec 28, 2024, 5:37 PM
Thanks, Jignesh. This is my fault. I wrote
==in the queryNaimish MakwanaPosted Dec 28, 2024, 12:43 PM
The query
SELECT salary FROM dbo.Employee WHERE 1=1;will return thesalarycolumn for all rows in theEmployeetable. The condition1=1is always true, so it doesn't filter out any rows. Essentially, this query retrieves the salary information for every employee in the table.Thanks