DEV Community

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

Posted on

1

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay