0% found this document useful (0 votes)
4 views2 pages

Order

The document is an SQL cheat sheet covering intermediate commands such as LIKE, BETWEEN, ORDER BY, GROUP BY, and HAVING, with syntax and examples for each. It provides clear explanations of how to use these commands to manipulate and query data in SQL databases. The document also includes a changelog detailing updates and edits made by various authors over time.

Uploaded by

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

Order

The document is an SQL cheat sheet covering intermediate commands such as LIKE, BETWEEN, ORDER BY, GROUP BY, and HAVING, with syntax and examples for each. It provides clear explanations of how to use these commands to manipulate and query data in SQL databases. The document also includes a changelog detailing updates and edits made by various authors over time.

Uploaded by

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

5/13/24, 12:08 PM about:blank

SQL Cheat Sheet: Intermediate - LIKE, ORDER BY, GROUP BY


Command Syntax Description Example
LIKE operator is used in a
WHERE clause to search for a
specified pattern in a column. SELECT f_name , l_name
FROM employees WHERE
SELECT column1, column2,
Two wildcards often used in address LIKE '%Elgin,IL%';
LIKE ... FROM table_name WHERE This command will output all
conjunction with the LIKE
columnN LIKE pattern;
operator are percent sign(%) and entries with Elgin,IL in the
underscore sign (_), depending Address.
upon the SQL engine being
used.
The BETWEEN operator selects SELECT * FROM employees
SELECT column_name(s) FROM values within a given range. The WHERE salary BETWEEN 40000
values can be numbers, text, or AND 80000;
BETWEEN table_name
WHERE
column_name BETWEEN value1 dates. The BETWEEN operator is This generates all records of
AND value2; inclusive: begin and end values employees with salaries between
are included. 40000 and 80000.
SELECT f_name, l_name,
dep_id FROM employees
ORDER BY keyword is used to ORDER BY dep_id DESC,
sort the result-set in ascending l_name;
SELECT column1, column2, or descending order. The default This displays the first name, last
ORDER ... FROM table_name ORDER is ascending. In case of multiple name, and department ID of
BY BY column1, column2, ... columns in ORDER BY, the employees, first sorted in
ASC|DESC; sorting will be done in the descending order of department
sequence of the appearance of IDs and then sorted
the arguments. alphabetically as per their last
names.
SELECT dep_id, COUNT(*)
FROM employees GROUP BY
GROUP BY clause is used in dep_id;
GROUP SELECT column_name(s) FROM collaboration with the SELECT This returns the department IDs
table_name GROUP BY
BY column_name(s) statement to arrange data with and the number of employees in
identical values into groups. them, grouped by the
department IDs.
HAVING clause is used in
conjunction with GROUP BY SELECT DEP_ID, COUNT(*) AS
clause in collaboration with the "NUM_EMPLOYEES",
SELECT column_name(s) FROM
table_name GROUP BY SELECT statement in order to AVG(SALARY) AS
HAVING "AVG_SALARY" FROM
column_name(s) HAVING filter the data as per the given EMPLOYEES GROUP BY DEP_ID
condition condition and then group as per HAVING count(*) < 4 ORDER
identical values of a specified BY AVG_SALARY;
parameter.

Author(s)
Lakshmi Holla
Abhishek Gagneja

about:blank 1/2
5/13/24, 12:08 PM about:blank

Changelog
Date Version Changed by Change Description
2023-10-03 1.3 Steve Hord QA pass with edits
2023-10-01 1.2 Abhishek Gagneja Updated the document
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