W3. SQL Exists Flashcards

1
Q

Q: What does the SQL EXISTS operator do?

A

A: It tests for the existence of any record in a subquery, returning TRUE if one or more records are found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: When does the EXISTS operator return TRUE?

A

A: When the subquery returns one or more records.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: Write the syntax for using EXISTS.

A

SELECT column_name(s)
FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE condition);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: Write a query to list suppliers with a product price less than 20 using EXISTS.

A

SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.SupplierID AND Price < 20);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: Write a query to list suppliers with a product price equal to 22 using EXISTS.

A

SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.SupplierID AND Price = 22);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly