Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

12/9/22, 10:06 AM https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DB0201EN-SkillsNetwork/labs/CheatSheet/SQL-Cheat-Sheet-Functions.md.html?origin=www.

co…

SQL Cheat Sheet: FUNCTIONS and Implicit JOIN

Command Syntax Description Example

COUNT SELECT COUNT(column_name)


FROM COUNT function returns the number of SELECT COUNT(dep_id) FROM
table_name
WHERE condition; rows that matches a specified criterion. employees;

AVG SELECT AVG(column_name)


FROM AVG function returns the average value SELECT AVG(salary) FROM employees;
table_name
WHERE condition; of a numeric column.

SUM SELECT SUM(column_name)


FROM SUM function returns the total sum of a SELECT SUM(salary) FROM employees;
table_name
WHERE condition; numeric column.

MIN SELECT MIN(column_name)


FROM MIN function returns the smallest value SELECT MIN(salary) FROM employees;
table_name
WHERE condition; of the SELECTed column.

MAX SELECT MAX(column_name)


FROM MAX function returns the largest value SELECT MAX(salary) FROM employees;
table_name
WHERE condition; of the SELECTed column.

ROUND SELECT ROUND(2number, decimals, ROUND function rounds a number to a SELECT ROUND(salary) FROM
operation) AS RoundValue; specified number of decimal places. employees;

LENGTH SELECT LENGTH(column_name)


FROM LENGTH function returns the length of a SELECT LENGTH(f_name) FROM
table; string (in bytes). employees;

UCASE SELECT UCASE(column_name) FROM UCASE function that displays the SELECT UCASE(f_name) FROM
table; column name in each table in employees;
uppercase.

DISTINCT SELECT DISTINCT(column_name) FROM DISTINCT function is used to display SELECT DISTINCT(UCASE(f_name)) FROM
table; data without duplicates. employees;

DAY SELECT DAY(column_name) FROM table DAY function returns the day of the SELECT DAY(b_date) FROM employees
month for a given date where emp_id = 'E1002';

CURRENT SELECT (CURRENT DATE - COLUMN) FROM CURRENT DATE is used to display the SELECT YEAR(CURRENT DATE - b_date)
DATE table; current date.This can be subtracted As AGE, CURRENT_DATE, b_date FROM
from the previous date to get the employees;
difference.

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

table1 [, table2 ]
[WHERE]) will be used in the main query as a SELECT * FROM ( SELECT emp_id,
condition to further restrict the data to f_name, l_name, dep_id FROM
be retrieved. employees) AS emp4all;

SELECT * FROM employees WHERE


job_id IN (SELECT job_ident FROM
jobs);

Implicit SELECT column_name(s)


FROM table1, Implicit Inner Join combines the two SELECT * FROM employees, jobs where
Inner Join table2
WHERE table1.column_name = or more records but displays only employees.job_id = jobs.job_ident;
table2.column_name; matching values in both tables.
Inner
join applies only the specified columns.

https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DB0201EN-SkillsNetwork/labs/CheatSheet/SQL-Cheat-Sheet-Functions.md.html?origin=www.coursera.org 1/2
12/9/22, 10:06 AM https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DB0201EN-SkillsNetwork/labs/CheatSheet/SQL-Cheat-Sheet-Functions.md.html?origin=www.co…

Implicit SELECT column_name(s)


FROM table1, Implicit Cross Join defines as a SELECT * FROM employees, jobs;
Cross Join table2; Cartesian product where the number
of rows in the first table multiplied by
the number of rows in the second
table..

Author(s)
Lakshmi Holla

Changelog
Date Version Changed by Change Description

2021-07-28 1.0 Lakshmi Holla Initial Version

https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DB0201EN-SkillsNetwork/labs/CheatSheet/SQL-Cheat-Sheet-Functions.md.html?origin=www.coursera.org 2/2

You might also like