Comprehensive Cheat Sheet for SQL

The most common SQL functions you must know

Aaron Zhu
Geek Culture

--

Photo by Alvin Engler on Unsplash

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 columns FROM a table
  • Use DISTICT operator inside the SELECT clause to remove duplicates rows. Keep in mind that DISTICT is not a function, therefore, no need to use parenthesis.
  • Use WHERE clause to filter rows based on one or more conditions with AND or OR logical operators.
  • Use ORDER BY clause to sort the result based on specific column(s) in ascending or descending…

--

--

Aaron Zhu
Geek Culture

Senior Data Analyst | Always looking for new and exciting ways to turn complex data into actionable insights | https://www.linkedin.com/in/aaron-zhu-53105765/