W3. SQL Where Flashcards
Q: What is the purpose of the SQL WHERE clause?
A: To filter records and extract only those that meet a specified condition.
Q: Write a SQL query to select all customers from Mexico.
SELECT * FROM Customers WHERE Country='Mexico';
Q: What is the general syntax for using the WHERE clause in SQL?
SELECT column1, column2, …
FROM table_name
WHERE condition;
Q: Can the WHERE clause be used in statements other than SELECT?
A: Yes, it can also be used in UPDATE, DELETE, and other statements.
Q: How should text and numeric values be formatted in the WHERE clause?
A: Text values should be enclosed in single (or double) quotes, but numeric values should not be enclosed in quotes.
Q: Write a query to select a customer with CustomerID equal to 1.
SELECT * FROM Customers WHERE CustomerID=1;
Q: Provide an example of a SQL query using a comparison operator to filter results.
SELECT * FROM Customers WHERE CustomerID > 80;
Q: List some operators that can be used in the WHERE clause.
= : Equal
> : Greater than
< : Less than
>= : Greater than or equal
<= : Less than or equal
<> or != : Not equal
BETWEEN : Between a certain range
LIKE : Search for a pattern
IN : Specify multiple possible values for a column