Comprehensive Cheat Sheet for SQL
The most common SQL functions you must know
SQL is one of the most popular programming languages for data science. Being able to write effective queries has become an essential skill for data science professionals. In this article, we will discuss the most commonly used SQL functions. Hopefully, this would be a helpful cheat sheet when writing SQL queries.
The SQL syntax used in this article is specifically applied to PostgreSQL. Query syntax might vary slightly for other SQL databases.
Queries
Let’s start with querying existing columns from a table. The following is the basic syntax.
SELECT [DISTINCT] column_1,
column_2
FROM table
WHERE (condition_1
AND condition_2)
OR condition_3
ORDER BY column_1 [DESC|ASC],
column_2 [DESC|ASC]
LIMIT #
- Use
SELECT
clause to pick specific columnsFROM
a table - Use
DISTICT
operator inside theSELECT
clause to remove duplicates rows. Keep in mind thatDISTICT
is not a function, therefore, no need to use parenthesis. - Use
WHERE
clause to filter rows based on one or more conditions withAND
orOR
logical operators. - Use
ORDER BY
clause to sort the result based on specific column(s) in ascending or descending…