SQL is a standard language for storing, manipulating, and retrieving data in databases. In this article, I’ll teach you the very basic fundamentals of the SQL language and hope you will be able to write your own database queries at the end.

What does SQL Mean?

SQL stands for Structured Query Language and lets you access and manipulate databases.

Syntax

Most of the actions you need to perform on a database are done with SQL statements. The following SQL statement selects all the records in the “Users” table:

SELECT * FROM Users;

Select

The select statement is used to retrieve data from a database. The requested data is returned in a results table.

SELECT column1 FROM table_name;

Select Distinct

The Select Distinct statement is used to return only distinct (different) values.

SELECT DISTINCT * FROM table_name;

Count

The following SQL statement lists the number of different customer countries:

SELECT COUNT(DISTINCT Country) FROM Customers;

Where

The Where clause is used to filter records.

SELECT column1
FROM table_name
WHERE condition;

For example:

SELECT * FROM Users
WHERE Country='Netherlands';

AND, OR and NOT Operators

The Where clause can be combined with AND, OR, and NOT operators. The AND and OR operators are used to filter records based on more than one condition:

  • The AND operator displays a record if all the conditions separated by AND are TRUE.
  • The OR operator displays a record if any of the conditions separated by OR is TRUE.

The NOT operator displays a record if the condition(s) is NOT TRUE.

AND

SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;

OR

SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;

NOT

SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;

#tech #guides-and-tutorials #sql #beginners-guide #programming

The Ultimate SQL Guide for Beginners in 2020.
1.15 GEEK