
For an instructor lead, in-depth look at learning SQL click below.
Welcome to the world of SQL, Structured Query Language, the core of data manipulation. In this blog post, we will go through the basics of SQL, a language built specifically for managing data held in a relational database management system.
The SELECT Statement
The SELECT statement is used to select data from a database. The data returned is stored in a result table, also called the result-set.
1 2 3 4 |
/* SQL SELECT Example */ SELECT * FROM Employees; |
Here, the asterisk (*) is used to select all columns from the “Employees” table.
Using the WHERE Clause
The WHERE clause is used to filter records, and is added after the table name. The WHERE keyword allows us to add conditions to our SQL command and thus select only certain records.
1 2 3 4 |
/*SQL WHERE Clause*/ SELECT * FROM Employees WHERE Country = 'USA'; |
This SQL statement selects all fields from “Employees” where country is ‘USA’.
The INSERT INTO Statement
It is used to insert new rows in a table.
1 2 3 4 5 |
/*SQL INSERT INTO Example*/ INSERT INTO Employees (FirstName, LastName, Age) VALUES ('John', 'Doe', 25); |
This SQL statement inserts a new record into the “Employees” table. The new record includes values for the FirstName, LastName, and Age.
The UPDATE Statement
The UPDATE Statement is used to modify the existing records in a table.
1 2 3 4 |
/* SQL UPDATE Example */ UPDATE Employees SET Age = 26 WHERE FirstName = 'John' and LastName = 'Doe'; |
This SQL statement updates the “Employees” table to set the age of ‘John Doe’ to 26.
The DELETE statement
The DELETE statement is used to delete existing records in a table.
1 2 3 4 |
/* SQL DELETE Example */ DELETE FROM Employees WHERE FirstName = 'John' and LastName = 'Doe'; |
This SQL statement deletes rows where the first name is ‘John’ and the last name is ‘Doe’ from the “Employees” table.
Conclusion – SQL Fundamentals
Now you can handle the most fundamental operations in SQL. Though these examples just scratched the surface, you are now capable of selecting, inserting, updating, and deleting data. Happy querying!