How to start learning SQL

Tarique Akhtar
2 min readJan 11, 2023

--

SQL is a powerful tool for managing and querying relational databases. It is a standard language used by various database management systems, such as MySQL, PostgreSQL, and Microsoft SQL Server. In this article, we will go over a simple SQL exercise that will help you get familiar with the basic concepts and syntax of SQL.

The first step in this exercise is to create a database and a table that we can work with. We will be using the SQLite database engine, which is a lightweight, file-based database engine that is perfect for learning and experimenting with SQL.

You should open the command prompt from Windows or terminal in iOS and write below command to start with.

To create a new SQLite database, you can use the following command:

sqlite3 mydatabase.db

This will open a SQLite prompt where you can enter SQL commands to interact with the database.

Next, we will create a table called “employees” with the following columns: id, name, and salary. The id column will be the primary key, and it will be an integer. The name column will be a text column, and the salary column will be a real column. You can create this table using the following SQL command:

CREATE TABLE employees (
id INTEGER PRIMARY KEY,
name TEXT,
salary REAL
);

Now that we have created a table, we can insert some data into it using the INSERT statement. For example, to insert a new employee into the employees table with an id of 1, a name of “John Smith”, and a salary of 50000, you would use the following command:

  INSERT INTO employees (id, name, salary) VALUES (1, 'John Smith', 50000);

You can insert as many rows as you want.

Once you have inserted some data into the table, you can use the SELECT statement to retrieve the data. The SELECT statement is used to select data from one or more tables in the database. For example, the following SQL command will retrieve all the rows from the employees table:

SELECT * FROM employees;

You can also use the WHERE clause to filter the results of a SELECT statement. For example, the following command will retrieve all the employees whose salary is greater than 40000:

SELECT * FROM employees WHERE salary > 40000;

In addition to SELECT and INSERT, SQL also has other statements such as UPDATE and DELETE, which you can use to modify and delete data in the database respectively.

This exercise is a great way to get started with SQL, and it should give you a good understanding of the basic syntax and concepts of the language. Remember that there are many other things you can do with SQL, such as creating indexes and views, joining tables, and using advanced query features such as subqueries and aggregate functions. The more you practice, the more comfortable and proficient you will become with SQL.

Thanks for reading.

--

--

Tarique Akhtar
Tarique Akhtar

Written by Tarique Akhtar

Data Science Professional, Love to learn new things!!!We can get connected through LinkedIn (https://www.linkedin.com/in/tarique-akhtar-6b902651/)

No responses yet