Member-only story
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
SELECTclause to pick specific columnsFROMa table - Use
DISTICToperator inside theSELECTclause to remove duplicates rows. Keep in mind thatDISTICTis not a function, therefore, no need to use parenthesis. - Use
WHEREclause to filter rows based on one or more conditions withANDorORlogical operators. - Use
ORDER BYclause to sort the result based on specific column(s) in ascending or descending…

