Please enable JavaScript.
Coggle requires JavaScript to display documents.
SQL (SELECT: SELECT colName FROM tableName (LIKE: selects all…
SQL
SELECT:
SELECT colName FROM tableName
TOP:
selects the two first records from the "Customers" table:
SELECT TOP 2 * FROM Customers;
selects the first 50% of the records from the "Customers" table:
SELECT TOP 50 PERCENT * FROM Customers;
LIKE:
selects all customers with a City starting with the letter "s":
SELECT * FROM Customers
WHERE City LIKE 's%';
selects all customers with a Country containing the pattern "land":
SELECT * FROM Customers
WHERE Country LIKE '%land%';
all customers with Country NOT containing the pattern "land":
WHERE Country NOT LIKE '%land%';
WILDCARDS:
% - zero or more characters
_ - a single character
[charlist] - ranges of characters to match
[^charlist] or [!charlist] - a character NOT specified in range
IN:
selects all customers with a City of "Paris" or "London":
SELECT * FROM Customers
WHERE City IN ('Paris','London');
BETWEEN :
all products with a price BETWEEN 10 and 20:
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
products outside the range:
WHERE Price NOT BETWEEN 10 AND 20;
all products with a price BETWEEN 10 and 20, but products with a CategoryID of 1,2, or 3:
WHERE (Price BETWEEN 10 AND 20)
AND NOT CategoryID IN (1,2,3);
all products with a ProductName beginning with any of the letter BETWEEN 'C' and 'M':
WHERE ProductName BETWEEN 'C' AND 'M';
DELETE:
DELETE FROM table_name
WHERE some_column=some_value;
DELETE FROM Customers
WHERE CustomerName='Alfreds Futterkiste' AND ContactName='Maria Anders';
Delete All Data:
DELETE FROM table_name;
DELETE * FROM table_name;
UPDATE:
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
UPDATE Customers
SET City='Hamburg'
WHERE CustomerID=1;
JOINED TABLES:
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
CREATE DB:
CREATE DATABASE dbname;
CREATE TABLE:
CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
Functions:
SELECT max(salary), employee_id, employee_name FROM Employee
The above SQL expression automatically returns the maximum salaried employee's details
INSERT
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
Comments:
Start with --
Multiline /
code
/
General Info: