Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

SQL-function12

The document provides SQL commands and functions for data manipulation, including aliasing columns, various types of joins (INNER, FULL OUTER, LEFT OUTER), and union operations. It also covers advanced SQL commands, time and date functions, string operations, mathematical functions, subqueries, and self-joins. Key points include the execution order of commands and the importance of table order in certain joins.

Uploaded by

Mace Chua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SQL-function12

The document provides SQL commands and functions for data manipulation, including aliasing columns, various types of joins (INNER, FULL OUTER, LEFT OUTER), and union operations. It also covers advanced SQL commands, time and date functions, string operations, mathematical functions, subqueries, and self-joins. Key points include the execution order of commands and the importance of table order in certain joins.

Uploaded by

Mace Chua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

AS FUNCTION – Creating an alias name for a column

SELECT column AS new name FROM table;


*Cannot be used in the WHERE and HAVING statement since it will be executed at the end
of the query
*Aggregate functions can be done to the column before renaming the column.

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”

WHERE talbe 2.column name IS null


*Add if the results wanted is exclusive to the data that is unique on the left table

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

ADVANCED SQL COMMANDS

SHOW – Displays the setup of the system/computer

TIME AND DATE FUNCTIONS


SELECT CURRENT_TIME
SELECT CURRENT_DATE
SELECT TIMEOFDAY()
SELECT NOW()
EXTRACT FUNCTION – To extract a subcomponent of a date value (Year, Month, Day, Week,
Quarter, DOW [Date of Week])
EXTRACT(SUBCOMPONENT FROM date column)

AGE FUNCTION – Computes the age of a timestamp from the current time/date
AGE(date column)

TO CHARACTER FUNCTION – Generally converts the given input to a character format


TO_CHAR(date column, ‘mm-dd-yyyy’ )

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

You might also like