Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
37 views
SQL Cheat Sheet
Uploaded by
Oana Batrinu
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save SQL Cheat sheet For Later
Download
Save
Save SQL Cheat sheet For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
37 views
SQL Cheat Sheet
Uploaded by
Oana Batrinu
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save SQL Cheat sheet For Later
Carousel Previous
Carousel Next
Save
Save SQL Cheat sheet For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 10
Search
Fullscreen
9124122, 459 PM SOL Cheat Sheet. Starter guide for standard SAL sya... | by Jason Lee | Towards Data Science To make Medium work, we log Privacy Po @ Publish... ... we You have 2 free member-only stories left this month, Sign up for Medium and get an extra one 3 Jason Lee (Follow) Apr 19,2020 . Sminread . + » Listen sve v Of & SQL Cheat Sheet Starter guide for standard SQL syntax used in PostgreSQL PostgreSQL cheatsheet by Jason Lee Photo by panumas nikhomkhai from Pexels SQL is the most important coding language to learn for data analysis. Some might i Ips:Mowardsdatascionce.comsq-cheat-sheot-776!8e3168!a 1109124122, 459 PM SOL Cheat Sheet. Starter guide for standard SAL sya... | by Jason Lee | Towards Data Science sow) Amazon, wh lata teams use SQL to query data and perform analysis. Like every language, you need to keep practicing to understand and grasp keep concepts. In my opinion, SQL is or guages to use once you SK Qe understand the basic structure of thy vw. «1 usw wticle, I share the necessary steps to getting started with SQL querying. Standard SQL Structure This is Part 1 to a series of PostgreSQL cheat sheets and will cover s WHERE, GROUP BY, HavING, oxpsR By and uiurr. The basic structure of a query pulling results from a single table is as follows. SELECT COLUMN_NAME (S) FROM TABLE_NAME, E CONDITION SROUP BY COLUMN_NAME (S) HAVING AGGREGATE_CONDITION ORDER BY COLUMN_NAME LIM N What is SQL? SQL (pronounced “ess-que-el”) stands for Structured Query Language. SQL is used to communicate with a database. It is the standard language for relational database management systems. SQL statements are used to perform tasks such as update data on a database or retrieve data from a database. a hitpsstowardsdatascionce.com/sqhcheat-shoot-776/803188!a 2109124122, 459 PM SOL Cheat Sheet. Starter guide for standard SQL sya... | by Jason Lee | Towards Data Science ow) © Rows — ais suvwii as recurs: + Columns — also known as fields, have a descriptive name and specific data type. What is PostgreSQL? PostgreSQL is a general-purpose and relational database management system, the most advanced open-source database system. Other common database management systems are MySQL, Oracle, IBM Db2, and MS. Access. Let's begin! SELECT The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set. Specific columns FROM TABLE_NAM All columns Using the - you can query every column in your table SRLROT + hitpsstowardsdatascionce.com/sqhcheat-shoot-776/803188!a a09124122, 459 PM SOL Cheat Sheet. Starter guide for standard SQL sya... | by Jason Lee | Towards Data Science ou sess) Finding all t DISTINCT (COLUMN NAME) FROM TABLE NAME ‘COUNT all rows If you want to know alll the values in the entire table use couvs(*) you will get a single number. SELEC’ FROM TABLE_NAME ‘COUNT DISTINCT values If you want the number of distinct values in a column using couvr with orsrmver and you will get a number representing the total unique values of a column SELECT COUNT (DISTINCT COLUMN_NAME) FROM TABLE_NAME, WHERE Using the wasar the clause, you can create conditions to filter out values you want or tl hitpsstowardsdatascionce.com/sqhcheat-shoot-776/803188!a ano9124122, 459 PM SOL Cheat Sheet. Starter guide for standard SAL sya... | by Jason Lee | Towards Data Science @0 To make Medium work our Privacy Policy, including g user data. By using N kie policy. TABLE_NAME, CONDITION Conditions There are a variety of conditions that can be used in SQL. Below are some examples of a table that consists of students’ grades in school. You only need to specify wese once, for the sake of the example, I have included wisks: in each step. FIRSTNAME = "BOB" = exact match FIRSTNAME I= "BOBT -- everything excluding BOB NO? FIRSTNAME ="BOB' =~ everything excluding BOB IN ('BOB', 'JASON') -- either condition is met NOT IN ('BOB', 'JASON') -~ excludes both values = 'BOB' AND LASTNAME = 'SMITH' -- both conditions = 'BOB' OR FIRSTNAME = 'JASON' -- either condition GRADES eater than 90 GRADES less than 90 GRADES greater than or equal to 90 GRADES less than or equal to 90 WHERE SUBJECT IS NULL -- returns values with missing values WHERE SUBJECT NOT NUL returns values with no missing values Conditions — Wildcards uke operator is used ina wuese clause to search for a specified pattern in a column. When you pass the i1x= operator in the ‘+ upper and lower case matters. There are two wildcards often used in conjunction with the u:x= operator: tl hitpsstowardsdatascionce.com/sqhcheat-shoot-776/803188!a 5109124122, 459 PM @0 To make Medium work WHERE FIhoswewin WHERE FIRSTNAME WHERE PIRSTNAME position WHERE PIRSTNAME position WHERE FIRSTNAME have at least 3 SOL Cheat Sheet. Starter guide for standard SQL sya... | by Jason Lee | Towards Data Science er data, By using Medium, you tated our Privacy Policy, including cookie policy. Bins pe "= Linus Values SLaLLuNy UppeLase BD LIKE ‘Sb’ -- finds values ending lowercase b LIKE ‘Sané’ -- find values that have “an” in any LIKE ‘_n%’ -- find values that have “n” in the second LIKE ‘B_%’ -- find values that start with “B” and characters in length LIKE ‘Btb’ -- find values that start with “B” and end WHERE FIRSTNAME with “b” WHERE FIRSTNAME .FY OR OLS WHERE FIRSTNAME ‘cr, OR YDt WHERE PIRSTNAME that start with WHERE FIRSTNAME starting with LIKE ‘[BFL]’ -- find all values that start with LIKE ‘(B-D]’ -- find all values that start with ‘BY, LIKE *[!BFL]%/ -- find everything exlcusing values ‘Br, SPOOR CL NOT LIKE *[BFL]$" -- same as above. excludes values 1 ET, OR SLE WHERE GRADES BETWEEN 80 and 90 -- find grades between 80 and 90 GROUP BY The rove sy function helps calculate summary values by the chosen column, Itis often used with aggregate functions (cous7, suv, av, vax, rv). SELECT “a tl hitpsstowardsdatascionce.com/sqhcheat-shoot-776/803188!a 6109124122, 459 PM SOL Cheat Sheet. Starter guide for standard SQL sya... | by Jason Lee | Towards Data Science e sess) ‘The query above will group each subject and calculate the average grades. SELECT SUBJECT, FROM GROUP BY ‘The above query will calculate the number (count) of students in each subject. HAVING The savine clause is similar to wees” but is catered for filtering aggregate functions. The savine function comes after the croup sy, in comparison the wares comes before the croup ay. If we wanted to find which subject had an average grade of 90 or more, we could use the following. SELECT SUBJECT, AVG (GRADES) FROM UDENT GROUP BY SUBJECT HAVING AVG (GRADES) >= 90 tt Q hitpsstowardsdatascionce.com/sqhcheat-shoot-776/803188!a m09124122, 459 PM SOL Cheat Sheet. Starter guide for standard SAL sya... | by Jason Lee | Towards Data Science ORDER BY Using the orper ey function, you can specity now you want your values sorted, Continuing with the Student tables from earlier. SELECT. FROM TUDENTS ORDER BY GRADES DESC When using the onssn sy by default, the sort will be in ascending order. If you want to descend, you need to specify orsc after the column name. LIMIT In Postgres, we can use the u1yz7 function to control how many rows are outputted in the query. For example, if we wanted to find the top 3 students with the highest grades. SELECT FROM STUDENTS ORDER BY GRADES DESC LIMIT 3 Since we use ompR BY © we have the order of students with the highest grades on top - now limiting it to 3 values, we see the top 3. hitpsstowardsdatascionce.com/sqhcheat-shoot-776/803188!a ano9124122, 459 PM ‘SQL Cheat Sheet. Starter guide for standard SAL. syntax... | by Jason Lee | Towards Data Science e sess) data froma sharing more SQL cheat sheets that will expand advanced syntax. If you want to learn specific techniques, check out my other tutorials. * Date/Time Function in SQL « Intro to Window Function: © Howto use CTEs in SQL * Creating Tables in SQL Sign up for The Variable By Towards Data Science Every Thursday, the Variable delivers the very best of Towards Data Science: from hands-on tutorials and cutting-edge research to original features you don't want to miss. Take a look, By signing up, you will ereate a Medium account ityou dont already have one. Review ‘our Privacy Policy for more information about our privacy practices. — Getinenewsietter) S Get this newsletter ) hitpsstowardsdatascionce.com/sqhcheat-shoot-776/803188!a9124122, 459 PM ‘SQL Cheat Sheet. Starter guide for standard SAL. syntax... | by Jason Lee | Towards Data Science ow) hitpsitowarcsdatascience.com/sql-cheat-a son0
You might also like
SQL Cheat Sheet - Scaler Topics
PDF
No ratings yet
SQL Cheat Sheet - Scaler Topics
17 pages
Data Analysis With SQL: Mysql Cheat Sheet
PDF
No ratings yet
Data Analysis With SQL: Mysql Cheat Sheet
4 pages
SQL Cheat Sheet
PDF
No ratings yet
SQL Cheat Sheet
15 pages
Cheat Sheet: Created by Tomi Mester
PDF
100% (1)
Cheat Sheet: Created by Tomi Mester
12 pages
SQL Cheat Sheet
PDF
100% (3)
SQL Cheat Sheet
21 pages
SQL Cheat Sheet For Data Scientists by Tomi Mester PDF
PDF
100% (1)
SQL Cheat Sheet For Data Scientists by Tomi Mester PDF
12 pages
SQL Cheat Sheet
PDF
No ratings yet
SQL Cheat Sheet
10 pages
SQL Cheat Sheet For Data Scientists by Tomi Mester 2019 PDF
PDF
100% (1)
SQL Cheat Sheet For Data Scientists by Tomi Mester 2019 PDF
12 pages
SQL Cheatsheet Zero To Mastery V1.01 PDF
PDF
No ratings yet
SQL Cheatsheet Zero To Mastery V1.01 PDF
20 pages
PostgreSQL Tutorial
PDF
No ratings yet
PostgreSQL Tutorial
25 pages
Select Modifying Data: SQL Cheat Sheet - Postgresql
PDF
No ratings yet
Select Modifying Data: SQL Cheat Sheet - Postgresql
3 pages
3 Notes of 3 Unit
PDF
No ratings yet
3 Notes of 3 Unit
36 pages
SQL Cheat Sheet ?
PDF
No ratings yet
SQL Cheat Sheet ?
10 pages
Data Analysis With SQL: Postgresql Cheat Sheet
PDF
No ratings yet
Data Analysis With SQL: Postgresql Cheat Sheet
4 pages
662a5089e0494246e350140dslides - Data Wrangling With SQL
PDF
No ratings yet
662a5089e0494246e350140dslides - Data Wrangling With SQL
85 pages
SQL 4
PDF
No ratings yet
SQL 4
12 pages
SQL
PDF
No ratings yet
SQL
9 pages
SQL - Structured Query Language A Standard That Specifies How
PDF
No ratings yet
SQL - Structured Query Language A Standard That Specifies How
66 pages
Postgre SQL Advance Notes
PDF
No ratings yet
Postgre SQL Advance Notes
23 pages
Net Database SQL 10
PDF
No ratings yet
Net Database SQL 10
18 pages
SQL_Cheat_Sheet_for_Beginners
PDF
No ratings yet
SQL_Cheat_Sheet_for_Beginners
3 pages
Introductory SQL 2
PDF
No ratings yet
Introductory SQL 2
43 pages
SQL_Cheat_Sheet
PDF
No ratings yet
SQL_Cheat_Sheet
5 pages
Postgresql
PDF
No ratings yet
Postgresql
6 pages
SQL Cheatsheet Zero To Mastery V1.01
PDF
No ratings yet
SQL Cheatsheet Zero To Mastery V1.01
19 pages
04 Advanced SQL Commands
PDF
No ratings yet
04 Advanced SQL Commands
78 pages
Select Modifying Data: SQL Cheat Sheet - Oracle
PDF
No ratings yet
Select Modifying Data: SQL Cheat Sheet - Oracle
3 pages
01 SQL Fundamentals
PDF
No ratings yet
01 SQL Fundamentals
149 pages
DBMS Unit3
PDF
No ratings yet
DBMS Unit3
33 pages
SQL Basics
PDF
No ratings yet
SQL Basics
8 pages
SQL Notes (2)
PDF
No ratings yet
SQL Notes (2)
25 pages
SQL - 1 cheat sheet
PDF
No ratings yet
SQL - 1 cheat sheet
5 pages
Lesson 3 Introduction To SQL
PDF
No ratings yet
Lesson 3 Introduction To SQL
66 pages
Standard SQL Functions Cheat Sheet Letter
PDF
No ratings yet
Standard SQL Functions Cheat Sheet Letter
2 pages
Select Joins: SQL Cheat Sheet
PDF
100% (1)
Select Joins: SQL Cheat Sheet
3 pages
Nebc Database Course Postgresql Cheat-Sheet V2 December 2008
PDF
No ratings yet
Nebc Database Course Postgresql Cheat-Sheet V2 December 2008
14 pages
SQL Commands
PDF
No ratings yet
SQL Commands
31 pages
Select Modifying Data: SQL Cheat Sheet - SQL Server
PDF
No ratings yet
Select Modifying Data: SQL Cheat Sheet - SQL Server
3 pages
Data Manipulation Language
PDF
No ratings yet
Data Manipulation Language
48 pages
SQL & Query Optimization: Unit - Iii
PDF
No ratings yet
SQL & Query Optimization: Unit - Iii
123 pages
02 SQL
PDF
No ratings yet
02 SQL
7 pages
04. SQL Queries, Clauses and Operators
PDF
No ratings yet
04. SQL Queries, Clauses and Operators
12 pages
Structured Query Language (SQL)
PDF
No ratings yet
Structured Query Language (SQL)
29 pages
SQL Part1
PDF
No ratings yet
SQL Part1
30 pages
An_Introduction_to_SQL_1731971471
PDF
No ratings yet
An_Introduction_to_SQL_1731971471
57 pages
Form of Basic SQL Query in DBMS
PDF
No ratings yet
Form of Basic SQL Query in DBMS
15 pages
7BCE5P1-Relational Database Lab
PDF
No ratings yet
7BCE5P1-Relational Database Lab
88 pages
SQL Cheat Sheet
PDF
No ratings yet
SQL Cheat Sheet
13 pages
Unit 3 notes DBMS final
PDF
No ratings yet
Unit 3 notes DBMS final
14 pages
List of SQL Commands Codecademy
PDF
No ratings yet
List of SQL Commands Codecademy
1 page
PostgreSQL Cheat Sheet - Hackr - Io
PDF
No ratings yet
PostgreSQL Cheat Sheet - Hackr - Io
90 pages
SQL Easy Steps
PDF
No ratings yet
SQL Easy Steps
5 pages
SQL Cheat Sheet
PDF
No ratings yet
SQL Cheat Sheet
62 pages
lab1 asmamaw-2
PDF
No ratings yet
lab1 asmamaw-2
19 pages
MYSQL
PDF
No ratings yet
MYSQL
1 page