Syntax
SELECT <the column you want to display> FROM <the table containing the data>
Select the product names from the Products table
SELECT prod_name FROM Products;
| prod_name |
| Fish bean bag toy |
| Bird bean bag toy |
| Rabbit bean bag toy |
| 8 inch teddy bear |
| 12 inch teddy bear |
| 18 inch teddy bear |
| Raggedy Ann |
| King doll |
| Queen doll |
Select the product ID, name and price from the Products table
SELECT prod_id, prod_name, prod_price FROM Products;
| prod_id | prod_name | prod_price |
| BNBG01 | Fish bean bag toy | 3.49 |
| BNBG02 | Bird bean bag toy | 3.49 |
| BNBG03 | Rabbit bean bag toy | 3.49 |
| BR01 | 8 inch teddy bear | 5.99 |
| BR02 | 12 inch teddy bear | 8.99 |
| BR03 | 18 inch teddy bear | 11.99 |
| RGAN01 | Raggedy Ann | 4.99 |
| RYL01 | King doll | 9.49 |
| RYL02 | Queen doll | 9.49 |
Select all columns from the Products table
SELECT * FROM Products;
| prod_id | vend_id | prod_name | prod_price | prod_desc |
| BNBG01 | DLL01 | Fish bean bag toy | 3.49 | Fish bean bag toy complete with bean bag worms with which to feed it |
| BNBG02 | DLL01 | Bird bean bag toy | 3.49 | Bird bean bag toy eggs are not included |
| BNBG03 | DLL01 | Rabbit bean bag toy | 3.49 | Rabbit bean bag toy comes with bean bag carrots |
| BR01 | BRS01 | 8 inch teddy bear | 5.99 | 8 inch teddy bear comes with cap and jacket |
| BR02 | BRS01 | 12 inch teddy bear | 8.99 | 12 inch teddy bear comes with cap and jacket |
| BR03 | BRS01 | 18 inch teddy bear | 11.99 | 18 inch teddy bear comes with cap and jacket |
| RGAN01 | DLL01 | Raggedy Ann | 4.99 | 18 inch Raggedy Ann doll |
| RYL01 | FNG01 | King doll | 9.49 | 12 inch king doll with royal garments and crown |
| RYL02 | FNG01 | Queen doll | 9.49 | 12 inch queen doll with royal garments and crown |
If you do not need every row in a table, limit the number of rows returned
SELECT TOP 5 cust_name FROM Customers;
SELECT cust_name FROM Customers LIMIT 5;
SELECT cust_name FROM Customers WHERE rownum <= 5;
SELECT cust_name FROM Customers FETCH FIRST 5 ROWS ONLY;
For more variations, see W3Schools
Select the first 5 rows from the Products table
SELECT prod_name FROM Products LIMIT 5;
| prod_name |
| Fish bean bag toy |
| Bird bean bag toy |
| Rabbit bean bag toy |
| 8 inch teddy bear |
| 12 inch teddy bear |
Select unique vend_id values from the Products table
SELECT DISTINCT vend_id FROM Products;
| vend_id |
| BRS01 |
| DLL01 |
| FNG01 |
-- This query is straightforward SELECT * -- All columns are selected here FROM Customers; -- LIMIT 1;
/* Do not remove this query yet SELECT * FROM Customers; LIMIT 1; */