
For an instructor lead, in-depth look at learning SQL click below.
Structured Query Language (SQL) is a standard language for interacting with databases. Regardless of the scale of your data, understanding SQL allows you to extract meaningful insights from it. Let’s get started with some basic SQL commands.
1. SELECT Statement
The SELECT statement is used to select data from a database. The data returned is stored in a results table, known as the result-set. Suppose we have a TABLE known as Customers, the SQL statement would be:
|
1 2 3 |
SELECT * FROM Customers; |
In the above command, * is used to select all columns. You can also select specific columns by replacing * with column names separated by a comma.
2. WHERE Clause
The WHERE clause is used to filter records that fulfill a specified condition. Below is an example:
|
1 2 3 |
SELECT * FROM Customers WHERE Country='Germany'; |
This SQL statement selects all fields from “Customers” where country is “Germany”.
3. INSERT INTO Statement
The INSERT INTO statement is used to insert new data into a database. Here is how we can insert new data:
|
1 2 3 |
INSERT INTO Customers (CustomerName, ContactName, Country) VALUES ('Cardinal', 'Tom B. Erichsen', 'Norway'); |
This SQL statement inserts a new record in the “Customers” table.
4. UPDATE Statement
The UPDATE statement is used to modify the existing records in a table. Below is an SQL statement that updates the “Customers” table to set ContactName to “Alfred Schmidt” where CustomerID is 1:
|
1 2 3 |
UPDATE Customers SET ContactName='Alfred Schmidt' WHERE CustomerID=1; |
5. DELETE Statement
The DELETE statement is used to delete existing records in a table. This is how we can delete a record:
|
1 2 3 |
DELETE FROM Customers WHERE CustomerName='Cardinal'; |
This SQL statement deletes the customer “Cardinal” from the “Customers” table.
Getting started with SQL isn’t complicated. In fact, becoming proficient at SQL is a pretty straightforward process and a skill that’s within reach of anyone involved in data analysis.
