Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT * FROM table_name;
- SELECT DISTINCT Country FROM Customers;
- SELECT * FROM Customers WHERE Country='Mexico';
- ===== AND, OR, NOT =====
- SELECT * FROM Customers
- WHERE Country='Germany' AND City='Berlin';
- SELECT * FROM Customers
- WHERE City='Berlin' OR City='München';
- SELECT * FROM Customers
- WHERE NOT Country='Germany';
- ===== ORDER BY =====
- SELECT * FROM Customers
- ORDER BY Country;
- SELECT * FROM Customers
- ORDER BY Country DESC;
- SELECT * FROM Customers
- ORDER BY Country ASC, CustomerName DESC;
- ===== INSERT INTO =====
- INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
- VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
- ===== NULL =====
- SELECT CustomerName, ContactName, Address
- FROM Customers
- WHERE Address IS NULL;
- SELECT CustomerName, ContactName, Address
- FROM Customers
- WHERE Address IS NOT NULL;
- ===== UPDATE =====
- UPDATE Customers
- SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
- WHERE CustomerID = 1;
- Be careful when updating records. If you omit the WHERE clause, ALL records will be updated!
- ===== DELETE =====
- DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';
- Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause, all records in the table will be deleted!
- ===== SELECT TOP =====
- SELECT TOP 3 * FROM Customers;
- SELECT TOP 50 PERCENT * FROM Customers;
- SELECT MIN(Price) AS SmallestPrice
- FROM Products;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement