Query Language
SELECT FROM WHERE
SELECT column_name,column_name
FROM table_name;
Per stampare intera tabella:
SELECT * FROM table_name;
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
SELECT TOP
SELECT TOP number|percent column_name(s)
FROM table_name;
esempio
SELECT TOP 2 * FROM Customers;
oppure
SELECT TOP 50 PERCENT * FROM Customers;
DISTINCT
In una tabella, una colonna può contenere molti valori duplicati; ed a volte si desidera solo elencare i valori distinti.
La parola chiave DISTINCT può essere utilizzata per restituire solo i valori distinti.
SELECT DISTINCT column_name,column_name
FROM table_name;
esempio
SELECT DISTINCT City FROM Customers;
ALIASES
L' Aliases sono usati per dare un nome temporaneo, ad una tabella o una colonna in una tabella , al interno del DB
SELECT column_name(s)
FROM table_name AS alias_name;
Le condizioni di ricerca
AND & OR
SELECT * FROM Customers
WHERE Country='Germany'
AND City='Berlin';
SELECT * FROM Customers
WHERE City='Berlin'
OR City='München';
SELECT * FROM Customers
WHERE Country='Germany'
AND (City='Berlin' OR City='München');
IN
*permette di specificare valori multipli nella clausola WHERE
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...);
BETWEEN
*sceglie i valori appartenenti ad una range
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
NOT
SELECT *
FROM suppliers
WHERE supplier_name NOT IN ( 'IBM', 'Hewlett Packard', 'Microsoft' );
SELECT *
FROM customers
WHERE customer_name IS NOT NULL;
SELECT supplier_name
FROM suppliers
WHERE supplier_name NOT LIKE 'T%';
SELECT *
FROM suppliers
WHERE supplier_id NOT BETWEEN 5000 AND 5500;
SELECT *
FROM suppliers
WHERE NOT EXISTS (SELECT * FROM orders WHERE suppliers.supplier_id = orders.supplier_id);
LIKE
* EFFETTUARE UNA RICERCA PARZIALE: LIKE
Operatore LIKE (viene utilizzato nella clausla WHERE per effettuare una ricerca)
SELECT * FROM studente
WHERE nome LIKE '*d*';