Skip to content

Vitor-Carmo/database-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Examples SQL

these are examples of sql commands for me, if I forget

SELECT

SELECT column1, column2, ...
FROM table_name;

SELECT DISTINCT

SELECT DISTINCT column1, column2, ...
FROM table_name;

SELECT WHERE

SELECT column1, column2, ...
FROM table_name
WHERE condition;

AND, OR, NOT

and:

SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;

or:

SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;

not:

SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;

ORDER BY

SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

INSERT INTO

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

NULL VALUES

SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NOT NULL;

UPDATE

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

DELETE

DELETE FROM table_name WHERE condition;

SELECT TOP

SQL Server / MS Access Syntax:

SELECT TOP number|percent column_name(s)
FROM table_name
WHERE condition;;

MySQL Syntax:

SELECT column_name(s)
FROM table_name
WHERE condition
LIMIT number;

Oracle Syntax:

SELECT column_name(s)
FROM table_name
WHERE ROWNUM <= number;

MIN, MAX

MIN

SELECT MIN(column_name)
FROM table_name
WHERE condition;

MAX

SELECT MAX(column_name)
FROM table_name
WHERE condition;

COUNT(), AVG() and SUM()

count()

SELECT COUNT(column_name)
FROM table_name
WHERE condition;

avg()

SELECT AVG(column_name)
FROM table_name
WHERE condition;

sum()

SELECT SUM(column_name)
FROM table_name
WHERE condition;

INNER JOIN

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;

LEFT JOIN

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;

RIGHT JOIN

SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;

FULL JOIN

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;

FULL JOIN

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;

ALTER TABLE

ALTER TABLE table_name
ADD column_name datatype;

ex:

ALTER TABLE Customers
ADD Email varchar(255);

Releases

No releases published

Packages

No packages published

Languages