SQL-function12
SQL-function12
INNER JOIN FUNCTION – Collects and presents data that are present in both tables
SELECT * FROM table 1 INNER JOIN table 2 ON table 1.column name = table 2.column name
*Table order does not matter
*When calling out results, if the column name is not unique the format should be followed
table name.column name
FULL OUTER JOIN FUNCTION – Matches all the data in both tables of the same columns but
places “null” on the data that do not have any match
SELECT * FROM table 1 OUTER JOIN table 2 ON table 1.column name = table 2.column
name
*Table order does not matter
*When calling out results, if the column name is not unique the format should be followed
table name.column name
FULL OUTER JOIN WHERE FUNCTION – Grabs the data that are not present in both columns
SELECT * FROM table 1 OUTER JOIN table 2 ON table 1.column name = table 2.column
name
WHERE table 1.column name IS null OR table 2.column name IS null
LEFT OUTER JOIN – Grabs the data that are present in both table but excludes the data that
is unique to only one table “right”
SELECT * FROM table 1 LEFT OUTER JOIN table 2 ON table 1.column name = table 2.column
name
*Table order does matter since it needs to specify which table is on the “left”
UNION FUNCTION – Gathers the data of both talbes of the same column
SELECT column name FROM table 1 UNION SELECT column name FROM table 2
AGE FUNCTION – Computes the age of a timestamp from the current time/date
AGE(date column)
STRING AND OPERATION FUNCTIONS – To create a string of text which can be extracted
from other columns (concatenation), such as making emails from the names of the clients
SELECT column 1 || column 2 FROM table
LEFT AND RIGHT FUNCTION – To grab a certain number of letters from a column
SELECT LEFT(column, number of characters) FROM table;
UPPER AND LOWER FUNCTION – To make the string of characters to be upper or lower
cased
SELECT UPPER(column) FROM table
MATHEMATICAL FUNCTIONS
SUBQUERY – Creating a new query statement inside another query statement using the
parenthesis operation
SELECT column FROM table
WHERE column > (SELECT AVG(column) FROM table )
*The query inside the parenthesis will be computed first
EXIST NOT EXIST FUNCTION – Checks if the rows exists in the in the actual returned
subquery
SELECT column FROM table
WHERE EXISTS (subquery)
SELFJOIN FUNCTION – Connecting information from the same table forming a new table
given the previous table’s information
SELECT table 1.column, table 2.column
FROM table AS table 1
JOIN table AS table 2
ON table 1.column = table 2.column
*All of these tables/data are found in one table, where table 1 and table 2 are just aliases