
For an instructor lead, in-depth look at learning SQL click below.
Greetings budding data enthusiasts! Today, we’re going to break down the basics of SQL fundamentals. SQL, or Structured Query Language, is the standard language for dealing with relational databases. Whether you’re a data scientist, a back-end developer or just a data enthusiast, know that SQL is a crucial skill in today’s data-driven world.
What Is SQL?
SQL stands for Structured Query Language. It’s a language designed to allow both technical and non-technical users query, manipulate, and transform data stored in a relational database. Also, it lets you create and modify databases.
The SELECT Statement
The SELECT
statement is used to select data from a database. The data returned is stored in a results table. Here’s a basic query:
1 2 3 4 |
SELECT * FROM Employees |
This code retrieves all data from the ‘Employees’ table. The asterisk (*) is a wildcard character that means “everything.”
The WHERE Clause
If you want to filter certain results from a table, the WHERE
clause is used. Check out this syntax:
1 2 3 4 5 |
SELECT * FROM Employees WHERE Country='USA' |
In this example, the query will retrieve information for all Employees where the ‘Country’ field is ‘USA’.
Inserting Data Into a Table
To add records into a table, we apply the INSERT INTO
statement. See this SQL code:
1 2 3 4 |
INSERT INTO Employees (FirstName, LastName, Country) VALUES ('John', 'Doe', 'USA') |
In this example, ‘John Doe’ from ‘USA’ is inserted in the ‘Employees’ table.
Updating an Existing Record
To modify records in a table, we use the UPDATE
statement. The following SQL code updates a record in the ‘Employees’ table where ‘EmployeeID’ is 1
1 2 3 4 5 |
UPDATE Employees SET FirstName = 'Anne', LastName = 'Smith' WHERE EmployeeID = 1 |
This command will update the ‘FirstName’ and ‘LastName’ of the employee with ‘EmployeeID’ 1 to ‘Anne Smith’.
More to Learn
While we just covered some of the basics, there’s a whole world to SQL waiting to be discovered, including joining tables, creating views, writing stored procedures, etc. Continue to experiment with these commands and see what you can create!
Stay curious, and happy querying!