SELECT <column1>, <column2> FROM <table> WHERE <column1 = 10 >
Select the product name and price from Products where the price is 3.49
-- Oracle / MySQL / SQL Server SELECT prod_name, prod_price FROM Products WHERE prod_price = 3.49;
| prod_name | prod_price |
| Fish bean bag toy | 3.49 |
| Bird bean bag toy | 3.49 |
| Rabbit bean bag toy | 3.49 |
| Operator | Description |
|---|---|
| = | Equal to |
| or != | Not equal to |
| < | Less than |
| <= | Less than or equal to |
| > | Greater than |
| >= | Greater than or equal to |
| BETWEEN x AND y | Between |
| NOT BETWEEN x AND y | Not between |
| IS NULL | Unknown / No value? |
| IS NOT NULL | Not unknown / Has a value? |
Operator reference: MySQL / MariaDB / SQLite, SQL Server, PostgreSQL, Oracle
Select the product name and price from Products where the price is less than 10
-- Oracle / MySQL / SQL Server SELECT prod_name, prod_price FROM Products WHERE prod_price < 10;
| prod_name | prod_price |
| Fish bean bag toy | 3.49 |
| Bird bean bag toy | 3.49 |
| Rabbit bean bag toy | 3.49 |
| 8 inch teddy bear | 5.99 |
| 12 inch teddy bear | 8.99 |
| Raggedy Ann | 4.99 |
| King doll | 9.49 |
| Queen doll | 9.49 |
Select the vendor ID and product name from Products where the vendor ID is not DLL01
-- Oracle / MySQL / SQL Server SELECT vend_id, prod_name FROM Products WHERE vend_id != 'DLL01';
| vend_id | prod_name |
| BRS01 | 8 inch teddy bear |
| BRS01 | 12 inch teddy bear |
| BRS01 | 18 inch teddy bear |
| FNG01 | King doll |
| FNG01 | Queen doll |
Note: quotes around 'DLL01' are required when filtering text values (strings)
Select the product name and price from Products where the price is between 5 and 10
-- Oracle / MySQL / SQL Server SELECT prod_name, prod_price FROM Products WHERE prod_price BETWEEN 5 AND 10;
| prod_name | prod_price |
| 8 inch teddy bear | 5.99 |
| 12 inch teddy bear | 8.99 |
| King doll | 9.49 |
| Queen doll | 9.49 |
BETWEEN 5 AND 10 includes both 5 and 10
Select all order numbers and dates from Orders with a date later than 1 February 2012
-- Oracle, SQL Server SELECT order_num, order_date FROM Orders WHERE order_date > '01-FEB-2012' ORDER BY order_date;
-- MySQL / SQL Server SELECT order_num, order_date FROM Orders WHERE order_date > '2012-02-01' ORDER BY order_date;
| order_num | order_date |
| 20008 | 2012-02-03 00:00:00 |
| 20009 | 2012-02-08 00:00:00 |
| 20005 | 2012-05-01 00:00:00 |
SELECT cust_name FROM Customers WHERE cust_email = NULL -- Unwanted
Select the customer name and email from Customers where the email field is NULL
-- Oracle / MySQL / SQL Server SELECT cust_name, cust_email FROM Customers WHERE cust_email IS NULL;
| cust_name | cust_email |
| Kids Place | NULL |
| The Toy Store | NULL |