Syntax
SELECT <wat je wil zien> FROM <tabel>
Selecteer de productnamen uit de tabel Products
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 |
Selecteer het product id, naam en prijs uit de tabel Products
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 |
Selecteer alle kolommen uit de tabel Products
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 |
Als je niet alle rijen van een tabel wil binnenhalen beperk je dan tot een aantal rijen
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;
Voor een meer variaties op W3Schools
Selecteer de eerste 5 rijen uit de tabel Products
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 |
Selecteer vend_id uit de tabel Products
SELECT DISTINCT vend_id FROM Products;
vend_id |
BRS01 |
DLL01 |
FNG01 |
-- Deze query is niet moeilijk SELECT * -- Hier worden alle kolommen geselecteerd FROM Customers; -- LIMIT 1;
/* Deze query nog niet weghalen
SELECT *
FROM Customers;
LIMIT 1; */