SQL SYNTAX : A QUICK GUIDE

Bendriss Maryam
Data Science in simple words
2 min readMay 31, 2022

We use SQL to manage relational databases and perform various operations on data in them. Within this tutorial, I make a summary of the SQL basics syntax as well as some tricks.

Enjoy Reading !!

DataBase is an organized collection of structured information, or data, typically stored electronically in a computer system.

To extract data from a table, we have to establish a request using SQL

The SELECT statement is used to select data from a database, using conditions or grouping.

— — — —

SELECT *

FROM Table

WHERE condition1 AND_OR condition 2

= / > / < / >= / <= /<> / BETWEEN / LIKE / IN / AND / OR / NOT

— — — —

SELECT column1, column2, …

FROM Table

WHERE NOT condition

— — — —

SELECT count(column1), column1

FROM Table

GROUP BY column1

→ The GROUP BY statement is often used with aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG())to group the result-set by one or more columns.

— — — —

SELECT DISTINCT column1, column2, …
FROM Table

— — — —

SELECT column1, column2, …
FROM Table
ORDER BY column1, column2, … ASC|DESC;

To combine rows from two or more tables, we have to make a join

— — — —

SELECT *
FROM Table1, Table2

WHERE Table1.PK = Table2.PK

— — — — —

SELECT column
FROM Table1
INNER JOIN Table2
ON Table1.column = Table2.column

→ The INNER JOIN selects records that have matching values in both tables

— — — — —

SELECT column
FROM Table1
LEFT JOIN Table2
ON Table1.column = Table2.column

→ The LEFT JOIN returns all records from the left table (Table1), and the matching records from the right table (Table2)

— — — — —

SELECT column
FROM Table1
RIGHT JOIN Table2
ON Table1.column = Table2.column

→ The RIGHT JOIN returns all records from the right table (Table1), and the matching records from the left table (Table2)

— — — — —

That was a quick summary of SQL syntax that can be useful to verify the syntax of your SQL queries.

To practice sql queries online, i suggest that you try : https://www.sql-practice.com/

--

--