
For an instructor lead, in-depth look at learning SQL click below.
SQL or Structured Query Language is the standard language for dealing with Relational Databases. SQL can be used to insert, search, update, and delete database records. But that’s not all, SQL lets you manage databases and perform various operations on the data.
Starting with SQL
Before writing SQL commands, it’s important we understand the basic anatomy of SQL. An SQL command is divided into clauses, expressions, predicates, queries, and statements. Perhaps that sounds a little overwhelming? Let’s break it down real quick.
Writing Your First SQL Query
1 2 3 4 |
/* This is the most basic form of an SQL query */ SELECT * FROM Employees; |
The ‘SELECT’ statement is used to select data from a database. The data returned is stored in a result table, called the result-set. ‘*’ is used to select all fields. ‘Employees’ is the table from which we want to select data.
Using Conditional Statements
SQL isn’t just about selecting data. It’s about selecting specific data that’s important for analysis. Let’s say we only wanted to select employees from the ‘Employees’ table with the job title ‘Engineer’.
1 2 3 4 |
/* This query will return all engineers from the Employees table */ SELECT * FROM Employees WHERE JobTitle='Engineer'; |
Inserting Data
Adding new data to your SQL database is an essential part of handling your data. To do this, we use the INSERT INTO command.
1 2 3 4 5 6 7 |
/* Inserting a new employee to the Employees table */ INSERT INTO Employees (Id, Name, JobTitle) VALUES (14, 'Sam', 'Engineer'); |
The above SQL statement will insert a new record into the ‘Employees’ table. The ‘Id’, ‘Name’, and ‘JobTitle’ fields will be filled with the values 14, ‘Sam’, and ‘Engineer’ respectively.
Wrapping Up
I hope this beginner-friendly insight into the world of SQL has been helpful. With these basics, you can begin to explore creating, querying, and manipulating databases. Remember, the best way to learn SQL, like any language, is by practicing.
1 2 3 |
/* Keep coding! */ |