Share This Post, Help Others, And Earn My Heartfelt Appreciation! :)
4.7
(3)

In this page we will focus on the SQL basics, especially on SQL SELECT statement. Firstly we will learn what is SQL – general introduction into the topic.

SQL SELECT Basics Complete online training

What does SQL mean?

SQL – stands for Structured Query Language. Using SQL you can manipulate the database. You can execute the following actions:

  1. DQL (Data Query Language):
    • execute queries (SELECT)
  2. DML (Data Manipulation Language):
    • insert data into database
    • update data in database
    • delete records from a database
  3. DDL (Data Definition Language):
    • create databases/tables/view
  4. DCL (Data Control Language):
    • grant permissions on tables, procedures or views

Basic SQL SELECT Syntax

The most basics and common command is SQL SELECT. The following query allow you to SELECT All columns from Select All columns from sales_report table. table. The * (star) means to select all columns from table. (SQL SELECT Basics Complete online training)

SELECT * FROM sales_report;

The example output is:

region                           |country            |item_type      |sales_channel|order_priority|order_date|order_id |ship_date |units_sold|unit_price|unit_cost|
---------------------------------+-------------------+---------------+-------------+--------------+----------+---------+----------+----------+----------+---------+
Middle East and North Africa     |Libya              |Cosmetics      |Offline      |M             |2020-12-20|686800706|2020-12-23|      8446|    437.20|   263.33|
North America                    |Canada             |Vegetables     |Online       |M             |2021-06-09|185941302|2021-06-17|      3018|    154.06|    90.93|
Middle East and North Africa     |Libya              |Baby Food      |Offline      |C             |2020-01-18|246222341|2020-01-25|      1517|    255.28|   159.42|
...

SELECT subset of columns

In the above example we selected all columns from sales_report table. Now we would like to see only specific columns by specifying then names separated by comma: region, country and item_type.

SELECT region, country, item_type from sales_report;

The following table sows the sample results of above SELECT statement:

region                           |country            |item_type      |
---------------------------------+-------------------+---------------+
Australia and Oceania            |Fiji               |Vegetables     |
Sub-Saharan Africa               |Togo               |Clothes        |
Europe                           |Montenegro         |Snacks         |
Europe                           |Greece             |Household      |
Europe                           |Montenegro         |Clothes        |
... 

SELECT Distinct

Distinct (in short) is used to fetch values with no duplicates for specific column or set of columns. Under the hood (in most cases) the database engine calculates the Distinct the same as Group By which you will learn in the next parts of this course. (SQL SELECT Basics Complete online training)

SELECT DISTINCT country FROM sales_report;

-- Output

country                         |
--------------------------------+
Indonesia                       |
Bangladesh                      |
Kiribati                        |
Cameroon                        |
Luxembourg                      |
Sweden                          |
...

The following example shows SELECT Distinct for multiple columns. Distinct Can be used to delete duplicates which for some reason exists in our data. (SQL SELECT Basics Complete online training)

SELECT DISTINCT region, country, item_type FROM sales_report;

-- Output

region|country               |item_type      |
------+----------------------+---------------+
Europe|France                |Vegetables     |
Asia  |Malaysia              |Office Supplies|
Europe|Germany               |Cereal         |
Europe|Romania               |Clothes        |
Asia  |Thailand              |Vegetables     |
Europe|Ireland               |Beverages      |
Europe|Iceland               |Office Supplies|
...

Summary

Now you can easily operate with your data using SELECT statement. In the next chapter, you’ll learn how to use the WHERE syntax, which gives you the ability to filter and restrict data to subsets that you would like to focus on. (SQL SELECT Basics Complete online training)

Have a sip of coffee and write the next chapter of your SQL adventure! 🙂

How useful was this post?

Click on a star to rate it!

Average rating 4.7 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments