W3. SQL In Flashcards

1
Q

Q: What does the SQL IN operator do?

A

A: It allows you to specify multiple values in a WHERE clause, acting as a shorthand for multiple OR conditions.

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

Q: Write a query to select all customers from ‘Germany’, ‘France’, or ‘UK’.

A

SELECT * FROM Customers
WHERE Country IN (‘Germany’, ‘France’, ‘UK’);

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

Q: What is the syntax for using the IN operator in SQL?

A

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, …);

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

Q: How do you exclude multiple values using IN?

A

A: Use NOT IN before the list of values, e.g., WHERE Country NOT IN (‘Germany’, ‘France’, ‘UK’).

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

Q: Write a query to select all customers who are NOT from ‘Germany’, ‘France’, or ‘UK’.

A

SELECT * FROM Customers
WHERE Country NOT IN (‘Germany’, ‘France’, ‘UK’);

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

Q: Can IN be used with a subquery?

A

A: Yes, IN can be used to match records in the main query with those in the result of a subquery.

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

Q: Write a query to select all customers who have an order in the “Orders” table.

A

SELECT * FROM Customers
WHERE CustomerID IN (SELECT CustomerID FROM Orders);

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

Q: What does NOT IN do when used with a subquery?

A

A: It selects records from the main query that do not match any in the subquery result.

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

Q: Write a query to return all customers who have NOT placed any orders.

A

SELECT * FROM Customers
WHERE CustomerID NOT IN (SELECT CustomerID FROM Orders);

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