...
An excellent SQL manual with examples and the ability to try different commands is given at link.
SELECT
SELECT - this is the basic command used to select data from the database. This command is usually used with the FROM command, which specifies which table to fetch data from. It is also possible to select from several tables - this will be described in the section JOIN. The default SELECT query looks like this:
...
SELECT DISTINCT - used to select unique values for a field. for instance:
SELECT DISTINCT column_1 FROM table_name;.
This query will print only unique values in column_1.
Learn more about SELECT DISTINCT and try how to work with it at link.SELECT TOP - is used to select the first N values from a field. For instance:
SELECT TOP 100 column_1 FROM table_name;.
This query will print only the first 100 values in column_1.
Learn more about SELECT TOP and try how to work with it at link.MIN/MAX - used to display the smallest or largest values in a column. For instance:
SELECT MIN(column_1) FROM table_name;.
This query will print the smallest value in column_1.
Learn more about MIN / MAX and try how to work with it at link.COUNT, AVG, SUM - COUNT () counts the number of rows in a column; AVG () displays the average of the column; SUM () - displays the sum of all values.
SELECT COUNT(column_1) FROM table_name;.
This query will print the number of rows in column_1.
SELECT AVG(column_1) FROM table_name;.
This query will print the average in column_1.
SELECT SUM(column_1) FROM table_name;.
This query will print the sum of all values in column_1.
Learn more about COUNT, AVG, SUM and try how to work with it at link.
WHERE
The WHERE command is used to create a selection condition:
...
Also in WHERE, user can work with columns that have NULL values (a field that has no value). The standard WHERE clauses do not work with NULL. You must use the IS NULL and IS NOT NULL operators. Learn more about IS NULL and IS NOT NULL and try how to work with it at link.
ORDER BY
ORDER BY command allows user to sort the data output according to certain rules.
...
Learn more about ORDER BY and try how to work with it at link.
JOIN
The JOIN command is used after the FROM command and is used to display columns in a query from different tables that are related to each other. So for example, if there is a PRODUCTS table with SKU_ID, GROUP_ID columns and there is a GROUPS table with GROUP_ID and GROUP_NAME columns, the JOIN will allow user to select SKU_ID and GROUP_NAME data from different tables, while linking them by GROUP_ID.
...
User can study and try each type of JOIN in more detail by following the links: (INNER) JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN.
GROUP BY
The GROUP BY command is used after the WHERE command and is used to group data by similarity. So, for example, user can group all products that have the same code. It is used if there are aggregating functions after SELECT in the query - such as COUNT, MAX, MIN, SUM, AVG, etc.
...