2. Interactive Guide to SQL

Vinayak Mathur
VLearn Together
Published in
4 min readJun 26, 2020

This article is for those people who have read the first article in the series, Interactive Guide to SQL. If you have not read the first article, you should read it to have a better understanding of what we are doing in SQL.
The first article deals with the basics and general ideas regarding SQL and different job profiles which require SQL. We cover the basic commands of SQL in that, here we will be taking a step further and learn about some complex statements.

Aggregate Functions: These functions perform a calculation over a set of values and return a single value. Also, use them with some clauses like GROUP BY and HAVING.
Some of the aggregate functions used in SQL are,
AVG(): We use this to calculate the average.

Figure 1
Figure 1 : Output

COUNT(): We use this to get the count of values in a particular column.

Figure 2
Figure 2: Output
Figure 3
Figure 3: Output

Note: COUNT() counts the values of rows, so if there is any NULL value, that would be processed by the COUNT() command.

MIN(): We use this to find out the minimum of the given values.

Figure 4
Figure 4: Output

MAX(): We use this to find out the maximum of the given values.

Figure 5
Figure 5: Output

SUM(): We use this to perform the addition of all the given values.

Figure 6
Figure 6: Output

Aliasing: As the name suggests, we use this to give new names to columns or tables to make them more readable.

Figure 7
Figure 7: Output

1. Column Aliasing: When we are querying data from any table, we use the SELECT command, but what if the names are not meaningful or are lengthy, then we use aliasing in SELECT.

2. Table Aliasing: When we have the same table names or a long table name, then we use Table Aliasing in SELECT this is done when using JOINS.
We will be looking at JOINS in the next article of this series but since I’ve brought it up let’s take a quick look at what it does.

Join: The JOIN clause helps us to connect different tables in a database which are logically related to each other in order to obtain meaningful results(query).

Sorting: We can use the ORDER BY clause in the SELECT statement to sort the results. Single column sort or multiple column sort is allowed. You can specify the type of sorting you want to perform. If you want your data to be sorted in ascending, then you can just use ORDER BY with SELECT as it is the default sorting but if you want to sort your records in a descending fashion then you can use the desc.

Figure 8
Figure 8: Output
Figure 9
Figure 9: Output

In this article, we took a closer look at SQL and some of its advanced queries.
These aggregate functions alongside with sorting will help you in manipulating data according to your requirement.
The commands and clauses in this article will prove to be beneficial for you irrespective of your role because these are fundamental commands that can be used by anyone.

If you like this article, please stay tuned because more complex queries will be taken up further in the series.
Happy Learning :)

--

--