W3. SQL Not Flashcards
Q: What does the SQL NOT operator do?
A: It returns the opposite or negative result of a specified condition.
Q: Write a query to select all customers that are NOT from Spain.
SELECT * FROM Customers WHERE NOT Country = 'Spain';
Q: What is the general syntax for using the NOT operator?
SELECT column1, column2, …
FROM table_name
WHERE NOT condition;
Q: How would you write a query to select customers whose names do not start with “A”?
SELECT * FROM Customers WHERE CustomerName NOT LIKE 'A%';
Q: Write a query to select customers with CustomerID not between 10 and 60.
SELECT * FROM Customers WHERE CustomerID NOT BETWEEN 10 AND 60;
Q: How do you use NOT with the IN operator to exclude certain values?
A: Use NOT IN, e.g., WHERE City NOT IN (‘Paris’, ‘London’);
Q: Write a query to select customers who are not from Paris or London.
SELECT * FROM Customers WHERE City NOT IN ('Paris', 'London');
Q: How do you select customers with a CustomerID not greater than 50?
SELECT * FROM Customers WHERE NOT CustomerID > 50;
Q: Is there an alternative syntax for “not greater than”?
A: Yes, !> can be used as a “not greater than” operator.
Q: How do you select customers with a CustomerID not less than 50?
SELECT * FROM Customers WHERE NOT CustomerID < 50;
Q: Is there an alternative syntax for “not less than”?
A: Yes, !< can be used as a “not less than” operator.