0% found this document useful (0 votes)
2 views2 pages

sql_cheatsheet

This document is a SQL cheatsheet that provides essential commands for data analysis. It includes basic SQL queries for selecting, filtering, sorting, and aggregating data, as well as instructions for performing joins and subqueries. The cheatsheet serves as a quick reference for executing common SQL operations.

Uploaded by

Chakshur Tyagi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

sql_cheatsheet

This document is a SQL cheatsheet that provides essential commands for data analysis. It includes basic SQL queries for selecting, filtering, sorting, and aggregating data, as well as instructions for performing joins and subqueries. The cheatsheet serves as a quick reference for executing common SQL operations.

Uploaded by

Chakshur Tyagi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

### SQL Cheatsheet for Data Analysis

#### Basic SQL Queries:

-- Select all columns from a table

SELECT * FROM table_name;

-- Select specific columns

SELECT column1, column2 FROM table_name;

-- Filter data with conditions

SELECT * FROM table_name WHERE condition;

-- Sorting the data

SELECT * FROM table_name ORDER BY column_name DESC; -- ASC for ascending order

-- Limit number of rows returned

SELECT * FROM table_name LIMIT 10; -- Fetch first 10 rows

-- Count rows in a table

SELECT COUNT(*) FROM table_name;

-- Group data by column

SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name;

-- Apply aggregate functions


SELECT AVG(column_name) FROM table_name; -- Average

SELECT SUM(column_name) FROM table_name; -- Sum

SELECT MIN(column_name) FROM table_name; -- Minimum

SELECT MAX(column_name) FROM table_name; -- Maximum

#### Joins:

-- Inner Join

SELECT * FROM table1

JOIN table2 ON table1.column_name = table2.column_name;

-- Left Join

SELECT * FROM table1

LEFT JOIN table2 ON table1.column_name = table2.column_name;

-- Right Join

SELECT * FROM table1

RIGHT JOIN table2 ON table1.column_name = table2.column_name;

#### Subqueries:

-- Subquery in WHERE clause

SELECT * FROM table_name WHERE column_name IN (SELECT column_name FROM

table_name WHERE condition);

-- Subquery in FROM clause

SELECT * FROM (SELECT column_name FROM table_name) AS subquery;

You might also like