
For an instructor lead, in-depth look at learning SQL click below.
SQL, or Structured Query Language, is an indispensable tool for managing data stored in a relational database management system (RDBMS), or for processing data streams in a relational data stream management system (RDSMS). SQL aids in enabling you to communicate with a database. This simple, yet powerful language is used to create, maintain and manipulate databases.
Today, we will uncover the true power of SQL through hands-on exercises.
1. Basic SELECT statement
The very first SQL command one must get familiar with is the SELECT statement. This command is used to select data from a database. The data returned is stored in a result table, often referred to as the result-set.
1 2 3 4 |
SELECT column1, column2, ... FROM table_name; |
Here, the column1, column2, … are the field names of the table you want to select data from. If you want to select all the fields available in the table, use the following syntax:
1 2 3 |
SELECT * FROM table_name; |
2. Distinct Rows
SQL SELECT DISTINCT Statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
1 2 3 4 |
SELECT DISTINCT column1, column2, ... FROM table_name; |
3. WHERE Clause
SQL WHERE clause is used to filter records and its added as part of a SQL statement. It’s a kind of a condition, only those who meet that condition will be returned.
1 2 3 4 5 |
SELECT column1, column2, ... FROM table_name WHERE condition; |
For instance, if we have a “Students” table and want to select All the students who have marks more than 60, then the SQL query would be like:
1 2 3 4 |
SELECT * FROM Students WHERE marks > 60; |
The SQL exercises we discussed are some of the fundamental practices that can set a firm foundation for your SQL learning journey. Keep practicing, keep solving real life problems and you will master SQL in no time.