You are on page 1of 2

6/21/23, 3:51 PM about:blank

SQL Cheat Sheet: FUNCTIONS and Implicit


JOIN

Command Syntax Description Example


SELECT COUNT(column_name) COUNT function returns the
COUNT FROM table_name WHERE number of rows that matches a SELECT COUNT(dep_id) FROM
employees;
condition; specified criterion.
AVG function returns the
SELECT AVG(column_name) FROM SELECT AVG(salary) FROM
AVG table_name WHERE condition;
average value of a numeric employees;
column.
SELECT SUM(column_name) FROM SUM function returns the total SELECT SUM(salary) FROM
SUM table_name WHERE condition; sum of a numeric column. employees;
MIN function returns the
SELECT MIN(column_name) FROM SELECT MIN(salary) FROM
MIN table_name WHERE condition;
smallest value of the employees;
SELECTed column.
MAX function returns the largest
SELECT MAX(column_name) FROM SELECT MAX(salary) FROM
MAX table_name WHERE condition;
value of the SELECTed employees;
column.
SELECT ROUND(2number, ROUND function rounds a
ROUND decimals, operation) AS number to a specified number SELECT ROUND(salary) FROM
employees;
RoundValue; of decimal places.
LENGTH function returns the
LENGTH SELECT LENGTH(column_name) SELECT LENGTH(f_name) FROM
FROM table; length of a string (in bytes). employees;
UCASE function that displays the
SELECT UCASE(column_name)
column name in each table in SELECT
UCASE(f_name) FROM
UCASE FROM table; employees;
uppercase.
DISTINCT function is used to SELECT
DISTINCT SELECT DISTINCT(column_name)
FROM table;
display data without DISTINCT(UCASE(f_name)) FROM
duplicates. employees;

SELECT DAY(column_name) FROM DAY function returns the day of SELECT DAY(b_date) FROM
DAY employees where emp_id =
table the month for a given date 'E1002';
is used to display SELECT YEAR(CURRENT DATE -
CURRENT DATE
CURRENT SELECT (CURRENT DATE - the current date.This can be b_date) As AGE,
DATE COLUMN) FROM table; subtracted from the previous CURRENT_DATE, b_date FROM
date to get the difference. employees;

Subquery SELECT column_name [, Subquery is a query within SELECT emp_id, fmame, lname,
column_name ] FROM table1 [, another SQL query and salary
table2 ] WHERE column_name
embedded within the WHERE FROM
employees
OPERATOR (SELECT column_name where salary
[, column_name ] FROM table1 clause. < (SELECT AVG(salary)
[, table2 ] [WHERE]) FROM employees);
A subquery is used to return
data that will be used in the

about:blank 1/2
6/21/23, 3:51 PM about:blank

main query as a condition to SELECT * FROM ( SELECT


further restrict the data to be emp_id, f_name, l_name,
dep_id FROM employees) AS
retrieved. emp4all;

SELECT * FROM employees


WHERE job_id IN (SELECT
job_ident FROM jobs);
Implicit Inner Join combines
SELECT column_name(s) FROM the two or more records but
Implicit table1, table2 WHERE displays only matching values SELECT * FROM employees,
jobs where employees.job_id
Inner Join table1.column_name = in both tables. Inner join = jobs.job_ident;
table2.column_name; applies only the specified
columns.
Implicit Cross Join defines
as a Cartesian product where
Implicit SELECT column_name(s) FROM SELECT * FROM employees,
the number of rows in the first jobs;
Cross Join table1, table2;
table multiplied by the number
of rows in the second table..

Author(s)
Lakshmi Holla

Changelog
Date Version Changed by Change Description
2023-05-04 1.1 Benny Li Formatting changes
2021-07-28 1.0 Lakshmi Holla Initial Version

about:blank 2/2

You might also like