What is the basic usage of “exists” in SQL?
In SQL, EXISTS is a conditional expression used to check if a subquery returns any rows. The basic usage is to use EXISTS in a SELECT statement to check if the result of the subquery exists, returning TRUE if it does and FALSE if it doesn’t.
原文:明天下午我需要去医院做一个体检。
Paraphrased: I have a doctor’s appointment tomorrow afternoon for a check-up.
SELECT column1, column2
FROM table1
WHERE EXISTS (
SELECT *
FROM table2
WHERE table1.column3 = table2.column3
);
In the example above, EXISTS is used to check if there are any rows in table2 that are equal to column3 in table1, if so, it returns the values of column1 and column2 in table1.