SQL stands for structured query language.
I’m not going to call SQL a programming language, as in my opinion, it’s not.
SQL is a query language. That means that when you piece the query language together, it’s to retrieve data based on the rules that your query defines.
There’s a lot (I repeat, a lot!) of uses for basic SQL.
Software Engineers uses SQL, data science uses SQL, data analytics uses SQL, heck, even accountants use SQL.
SQL skills and thought process can also be translated to a lot of different ETL based tasks.
If you know the SQL basics, you can boost your employability for sure.
You also don’t need a lot to start to learn. A decent laptop and a free mySQL install and you’re good to go.
In my mind, learning of any programming related topic is not a sprint, it’s a marathon. With that in mind though, lets' look at some realistic timelines for learning SQL.
Structured query language (SQL) is common anywhere that requires database systems.
And guess where database systems are used? Pretty much everywhere.
If you are interested in data analytics, data science, software engineering, or database management, you will need to know SQL.
Learning SQL can also lead to high-paying jobs that involve other programming languages.
For starters, you need to be able to dedicate some time to learning.
When I started as a Junior Software Engineer 20 years ago, I was fortunate enough to get paid to learn. I was able to spend hours reading, taking courses and practicing in real world experiences.
If you can learn on the job, it’s certainly easier. You may be cross training from other programming languages, or from a completely different department.
Either way, being in the proximity of a SQL developer aids the learning process, that’s for sure.
If you are not learning on the job, there are lots of amazing course providers out there that offer courses in both basic SQL and advanced SQL skills. Without someone to guide you through though, factor in that this will take a little longer.
Let’s quickly go through the basics:
-- Select all columns from the 'users' table
SELECT *
FROM users;
-- Select specific columns (e.g., 'id', 'name') from the 'users' table
SELECT id, name, email
FROM users
WHERE status = 'active';
-- Insert a single row into the 'users' table
INSERT INTO users (id, name, email, status)
VALUES (1, 'John Doe', '[email protected]', 'active');
-- Insert multiple rows into the 'users' table
INSERT INTO users (id, name, email, status)
VALUES
(2, 'Jane Smith', '[email protected]', 'inactive'),
(3, 'Sam Wilson', '[email protected]', 'active');
-- Update the 'status' column for a specific user
UPDATE users
SET status = 'inactive'
WHERE id = 1;
-- Update multiple columns for users with a certain condition
UPDATE users
SET email = '[email protected]', status = 'active'
WHERE name = 'Jane Smith';
-- Delete a specific row based on a condition
DELETE FROM users
WHERE id = 1;
-- Delete all rows where status is 'inactive'
DELETE FROM users
WHERE status = 'inactive';
Learning these basic SQL concepts can be done in a few days.
How long does it take to learn SQL to an intermediate level? A year or two to do it properly.
Intermediate sql skills here.
SQL Functions, JOINs, Subqueries and CTEs.
This is to learn how to manipulate data using SQL queries.
INNER JOIN with a WHERE clause.
-- Retrieve users and their corresponding orders
SELECT users.id, users.name, orders.order_id, orders.amount
FROM users
INNER JOIN orders ON users.id = orders.user_id
WHERE orders.amount > 100;
This query joins the ‘users’ table and the ‘orders’ table where the ‘id’ in ‘users’ matches the ‘user_id’ in ‘orders’.
LEFT JOIN
-- Retrieve all users and their orders (include users with no orders)
SELECT users.id, users.name, orders.order_id, orders.amount
FROM users
LEFT JOIN orders ON users.id = orders.user_id;
-- Use a CTE to retrieve users with high order amounts
WITH HighSpendingUsers AS (
SELECT users.id, users.name, SUM(orders.amount) AS total_spent
FROM users
INNER JOIN orders ON users.id = orders.user_id
GROUP BY users.id, users.name
HAVING SUM(orders.amount) > 500
)
SELECT *
FROM HighSpendingUsers;
-- Explanation:
-- 1. The CTE 'HighSpendingUsers' calculates the total spent by each user.
-- 2. Only users with a total order amount greater than 500 are included.
-- 3. The main query selects all results from the CTE.
-- Retrieve users and the total amount of their orders
SELECT
id,
name,
(SELECT SUM(amount) FROM orders WHERE orders.user_id = users.id) AS total_spent
FROM users;
Practice with complex queries and data analysis using the above features and you’ll be well in to your intermediate SQL skills level.
How long does it take to learn SQL to an advanced level? Probably years.
Everyones learning process is different, but to truly master the above skill set and understand not only how to use the features, but when to use them should be achievable in 3 to 6 months depending on how many hours a day you are able to practice and learn.
Let’s move on the advanced SQL functions.
A stored procedure is a collection of individual SQL statements placed together to make a reusable set of combined functionality.
You would usually pass a few parameters in to the stored procedure, it would use those parameters to define the data required and then return you something hopefully useful.
-- Create a stored procedure to fetch user details by user ID
CREATE PROCEDURE GetUserById
@UserId INT
AS
BEGIN
-- Select statement to return the user object
SELECT id, name, email, status
FROM users
WHERE id = @UserId;
END;
Above, we have a stored procedure. It takes userId as an input, and returns a row of data from the ‘users’ table, containing the columns: Id, name, email and status.
To execute the stored procedure, we simply:
-- Execute the stored procedure with a specific UserId
EXEC GetUserById @UserId = 1;
and it returns (assuming the data is present):
id | name | email | status
1 | John Doe | [email protected] | active
Advanced users will need to take time to learn about database performance.
Sometimes you will have a database administrator to help you with this, but other times as an engineer, you’ll be on your own.
Advanced SQL then isn’t just about syntax, it’s about understanding how to write complex queries to manipulate data on a relational database.
As always with programming languages, you need to start at the beginning and take your time.
I learned on the job and picked a lot up as I went as and when I needed.
My SQL skills came as I needed to solve new problems and manipulate data in ways I hadn’t before.
Learning SQL for me was a mix of reading books (this was 20 years ago!), taking courses, pair programming and diving deep when coming across a stumbling block in a project.
Practice as often as you can with real world scenarios. There’s nothing better than solving an actual problem rather than a contrived example.
Get involved with communities. The microsoft sql server groups on LinkedIn are great. Friendly people with a lot of knowledge.
As always, questions like this are very hard to answer universally.
The time it takes to learn SQL can really vary depending on your background, the time you get to spend learning and your aptitude towards this type of task.
If you have no programming knowledge, learning very basic SQL skills can take up to around two weeks.
Intermediate SQL skills can be picked up in the first few months of dedicated work, and I’d say that advanced SQL skills will take up to a year of solid work.
If you are already familiar with other programming languages and have prior programming experience, or have used relational databases before, learning SQL could be much faster than that.
Just remember, don’t be hard on yourself. It takes time and most people genuinely have what it takes to learn SQL.