Skip to main content

SQL Cheat sheet

This cheat sheet provides a quick reference for some of the most commonly used SQL operations, including basic data retrieval, filtering and sorting, data modification, and aggregation. Whether you are a beginner or an experienced SQL user, this cheat sheet can serve as a handy reminder of the syntax and functionality of the SQL language.

Basic Operations:

SELECT: Retrieve data from a table

Syntax: SELECT column1, column2, ... FROM table_name;


WHERE: Filter data based on conditions

Syntax: SELECT column1, column2, ... FROM table_name WHERE condition;


LIMIT: Limit the number of returned rows

Syntax: SELECT column1, column2, ... FROM table_name LIMIT number_of_rows;


ORDER BY: Sort data in ascending or descending order

Syntax: SELECT column1, column2, ... FROM table_name ORDER BY column_name [ASC | DESC];


UPDATE: Modify data in a table

Syntax: UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;


DELETE: Remove data from a table

Syntax: DELETE FROM table_name WHERE condition;


INSERT INTO: Add data to a table

Syntax: INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);


Joining Tables:

INNER JOIN: Retrieve data that matches in both tables

Syntax: SELECT column1, column2, ... FROM table1 INNER JOIN table2 ON condition;


LEFT JOIN (or LEFT OUTER JOIN): Retrieve all data from the left table and matching data from the right table

Syntax: SELECT column1, column2, ... FROM table1 LEFT JOIN table2 ON condition;


RIGHT JOIN (or RIGHT OUTER JOIN): Retrieve all data from the right table and matching data from the left table

Syntax: SELECT column1, column2, ... FROM table1 RIGHT JOIN table2 ON condition;


FULL OUTER JOIN: Retrieve all data from both tables

Syntax: SELECT column1, column2, ... FROM table1 FULL OUTER JOIN table2 ON condition;


Aggregate Functions:

COUNT: Count the number of rows

Syntax: SELECT COUNT(column_name) FROM table_name;


SUM: Calculate the sum of values in a column

Syntax: SELECT SUM(column_name) FROM table_name;


AVG: Calculate the average of values in a column

Syntax: SELECT AVG(column_name) FROM table_name;


MIN: Retrieve the minimum value in a column

Syntax: SELECT MIN(column_name) FROM table_name;


MAX: Retrieve the maximum value in a column

Syntax: SELECT MAX(column_name) FROM table_name;


GROUP BY: Group data by a column and apply aggregate functions to each group

Syntax: SELECT column1, SUM(column2), ... FROM table_name GROUP BY column1;

This cheat sheet provides a basic understanding of SQL and covers the most commonly used operations. However, this is not an exhaustive list and SQL has many other features and functions.

Comments

Popular posts from this blog

AI School: How to Use Chat GPT

Chat GPT changed the conversation about artificial intelligence - the technology that is predicted to revolutionize how businesses and individuals interact with computers. Despite its impressive potential, the service is far from user-friendly in all aspects. In a series of articles, Techsavvyminds tests and guides you, the reader, through the basics of the most talked-about AI services. First up is Chat GPT from the American company Open AI. Over half a year has passed since Chat GPT transformed the conversation about artificial intelligence. For companies, it has been said that AI can streamline everyday tasks by taking over repetitive tasks, assisting with presentation materials, and even handling email conversations. Although the hype has been hard to miss, it hasn't been obvious to everyone to explore the possibilities of this new technology. Others have tried and realized that the shortcomings are still too significant to make a real difference in everyday life. The only way ...

How to append queries in Power BI

To append queries in Power Query, you can use the "Append" transformation, which allows you to combine two or more tables by adding the rows from one table to the bottom of another table. Here is how you can do this in Power Query: 1. Open the Power Query Editor and select the tables that you want to append. 2. Click the "Home" tab in the ribbon, and then click the "Append" button in the "Combine" group. 3. In the "Append" dialog box, select the table that you want to append to the bottom of the other table, and then click "OK". Power Query will create a new query that combines the two tables by appending the rows from one table to the bottom of the other. You can then apply additional transformations as needed, and load the resulting table back into your workbook or report. Alternatively, you can also use the "Merge" transformation to combine two tables by matching rows from one table with rows from the other table ...

5 Proven Strategies to Pass the Microsoft Power BI Data Analyst - PL-300 Exam

Earning a certification in Power BI as a data analyst is a great way to validate your skills, enhance your career prospects, improve your skills, enhance your credibility, and demonstrate your commitment to professional development. To excel in this exam, candidates must have a strong grasp of Power Query and proficiency in writing Data Analysis Expressions (DAX). They should also possess knowledge in assessing data quality and be familiar with data security measures such as row-level security and data sensitivity.  The following skills are evaluated:  Prepare the data (25–30%) Model the data (25–30%) Visualize and analyze the data (25–30%) Deploy and maintain assets (15–20%) The Microsoft PL-300 exam is designed for candidates who want to validate their skills as Data Analysts. Here are some tips to help you prepare for and pass the PL-300 exam: 1. Review the exam objectives:  The first step in preparing for any exam is to review the exam objectives. These objectives pro...