What does the SQL Server Exists
function return as a type?
Does Exists
have a conceptual return type?
SELECT *
FROM tableName
WHERE EXISTS (SELECT *
FROM tableName
WHERE columnName LIKE 'theValue%') = 1
Why does this not work?
The EXISTS operator is used to test for the existence of any record in a subquery. The EXISTS operator returns TRUE if the subquery returns one or more records.
To test whether a row exists in a MySQL table or not, use exists condition. The exists condition can be used with subquery. It returns true when row exists in the table, otherwise false is returned. True is represented in the form of 1 and false is represented as 0.
“IN” clause is preferred when there is a small list of static values or the inner query returns a very less number of rows. “EXISTS” clause is preferred when there is a need to check the existence of values in another table or when there is a need to check against more than one column.
If EXISTS (subquery) returns at least 1 row, the result is TRUE. If EXISTS (subquery) returns no rows, the result is FALSE. If NOT EXISTS (subquery) returns at least 1 row, the result is FALSE.
As documented in BOL
Result Types
Boolean
It has a return type of boolean but this is just an internal datatype currently you can't declare columns or variables of that datatype.
Or use it in comparisons - even against another boolean.
where exists(select 1) = exists(select 1)
Also fails.
SQL Server doesn't implement the SQL Standard boolean datatype yet - the closest equivalent is bit
but this is not a true boolean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With