Server SQL Server-----EXISTS ()
EXISTS
Specifies a subquery that detects the existence of a row.
is a restricted SELECT statement (COMPUTE clauses and into keywords are not allowed). For more information, see the discussion of subqueries in SELECT.
Result type
Boolean
Result value
Returns TRUE if the subquery contains rows.
But be aware:
Using NULL in a subquery still returns the result set
This example specifies NULL in the subquery and returns the result set, which is still TRUE by using EXISTS.
Use Northwind
Go
SELECT CategoryName
From Categories
WHERE EXISTS (SELECT NULL)
ORDER BY CategoryName ASC
Go
In this case, pay special attention to such use, such as the following example:
If EXISTS (select Ticket from table where id= 5)
Return
Else
Update .......
If the query id=5 the ticket column of this row and the value is exactly null, the EXISTS still evaluates to TRUE so that it will only perform return.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.