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.
SQL stands for Structured Query Language and lets you access and manipulate databases.
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;
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;
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;
The Where clause is used to filter records.
SELECT column1
FROM table_name
WHERE condition;
For example:
SELECT * FROM Users
WHERE Country='Netherlands';
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 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