DEV Community

Cover image for SQL Notebook I Wish I Had Crafted Sooner in My Coding Path
silverboi
silverboi

Posted on

SQL Notebook I Wish I Had Crafted Sooner in My Coding Path

BigQuery is very similar to SQL and is easy so here is my cheatsheet.

  • SELECT:
SELECT * FROM table;
SELECT ... FROM ... WHERE condition
SELECT ... FROM ... WHERE condition GROUP BY field;
SELECT ... FROM ... ORDER BY field1, field2 ASC;
SELECT ... FROM ... WHERE condition ORDER BY field1, field2 DESC;
SELECT ... FROM ... LIMIT 10;
SELECT DISTINCT field1 FROM ... table;
SELECT DISTINCT field1, field2 FROM ... table;
Enter fullscreen mode Exit fullscreen mode
  • CONDITIONS:
field1 = value1
t1.field = t2.field
field1 <> value1
field1 LIKE 'value _ %'
field1 IS NULL
field1 IS NOT NULL
field1 IS IN (value1, value2)
field1 IS NOT IN (value1, value2)
condition1 AND condition2
condition1 OR condition2
Enter fullscreen mode Exit fullscreen mode
  • AGGREGATION FUNCTIONS:
MAX()
MIN()
AVG()
CONCAT()
STRING_AGG()
Enter fullscreen mode Exit fullscreen mode
  • COMMON TABLE EXPRESSIONS (CTE):
WITH CTE_table_name AS ( query );
Enter fullscreen mode Exit fullscreen mode
  • JOINS:

Image taken from https://levelup.gitconnected.com/mastering-sql-joins-boost-your-database-query-skills-69649618769d

Silverboy

Top comments (0)