SQL Programming Resources
75.8K subscribers
510 photos
13 files
453 links
Find top SQL resources from global universities, cool projects, and learning materials for data analytics.

Admin: @coderfun

Useful links: heylink.me/DataAnalytics

Promotions: @love_data
Download Telegram
SQL Roadmap โœ…
๐Ÿ‘9โค5
Commit and master ๐—ฆ๐—ค๐—Ÿ in just ๐Ÿฏ๐Ÿฌ ๐——๐—ฎ๐˜†๐˜€!

I've outlined a simple, actionable plan for you to followโ€ฆ

๐—ช๐—ฒ๐—ฒ๐—ธ ๐Ÿญ: ๐—•๐—ฎ๐˜€๐—ถ๐—ฐ๐˜€ ๐—ผ๐—ณ ๐—ฆ๐—ค๐—Ÿ

โž› Day 1-2: Introduction to SQL, setting up your environment (MySQL/PostgreSQL/SQL Server).

โž› Day 3-4: Understanding databases, tables, and basic SQL syntax.

โž› Day 5-7: Working with SELECT, WHERE, and filtering data.

๐—ช๐—ฒ๐—ฒ๐—ธ ๐Ÿฎ: ๐—–๐—ผ๐—ฟ๐—ฒ ๐—ค๐˜‚๐—ฒ๐—ฟ๐—ถ๐—ฒ๐˜€

โž› Day 8-10: Using JOINs โ€“ INNER, LEFT, RIGHT, FULL.

โž› Day 11-13: GROUP BY, HAVING, and aggregate functions (SUM, COUNT, AVG).

โž› Day 14: Practice session โ€“ write complex queries.

๐—ช๐—ฒ๐—ฒ๐—ธ ๐Ÿฏ: ๐— ๐—ผ๐—ฑ๐—ถ๐—ณ๐˜†๐—ถ๐—ป๐—ด ๐——๐—ฎ๐˜๐—ฎ

โž› Day 15-17: INSERT, UPDATE, DELETE โ€“ altering your data.

โž› Day 18-20: Subqueries, nested queries, and derived tables.

โž› Day 21: Practice session โ€“ work on a mini-project.

๐—ช๐—ฒ๐—ฒ๐—ธ ๐Ÿฐ: ๐—”๐—ฑ๐˜ƒ๐—ฎ๐—ป๐—ฐ๐—ฒ๐—ฑ ๐—ฆ๐—ค๐—Ÿ ๐—ง๐—ผ๐—ฝ๐—ถ๐—ฐ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ฃ๐—ฟ๐—ผ๐—ท๐—ฒ๐—ฐ๐˜

โž› Day 22-24: Window functions, RANK, DENSE_RANK, ROW_NUMBER.

โž› Day 25-27: Creating and managing indexes, views, and stored procedures.

โž› Day 28-30: Capstone project โ€“ work with real-world data to design and query a database.

Here you can find SQL Interview Resources๐Ÿ‘‡
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v

Like this post if you need more ๐Ÿ‘โค๏ธ

Share with credits: https://t.iss.one/sqlspecialist

Hope it helps :)
โค5๐Ÿ‘3
SQL Number Functions ๐Ÿ‘†
๐Ÿ‘7โค2
SQL Joins โœ…
๐Ÿ‘5โค4๐Ÿ‘1
SQL books wonโ€™t teach you this.

Natural Keys vs. Autoincrement IDs vs. Public IDs. (or maybe all together)


๐—ก๐—ฎ๐˜๐˜‚๐—ฟ๐—ฎ๐—น ๐—ž๐—ฒ๐˜†๐˜€

Natural keys carry intrinsic meaning because they are part of the domain.

They are directly related to the data, making them intuitive and easy to understand. Examples include email addresses or employee IDs.

The problem is that they are usually not good for performance, but they can also be a security risk if you expose them.


๐—”๐˜‚๐˜๐—ผ๐—ถ๐—ป๐—ฐ๐—ฟ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—œ๐——๐˜€

Autoincrement IDs automatically generate unique integers to identify rows within a table.

They are often used as primary keys.

Simple integers are fast for the database to index and query. They provide optimal performance.

However, they are vulnerable to enumeration attacks since predicting the next or previous record is easy.


๐—ฃ๐˜‚๐—ฏ๐—น๐—ถ๐—ฐ ๐—œ๐——๐˜€ (๐—จ๐—จ๐—œ๐——๐˜€)

UUIDs (Universally Unique Identifiers) are 128-bit identifiers used to uniquely identify information without relying on a centralized authority.

They are difficult to guess, making them suitable for public exposure in APIs.

The problem is they are larger and more complex than integers. This can impact performance, particularly in indexing and storage.


๐—™๐—ถ๐—ป๐—ฑ๐—ถ๐—ป๐—ด ๐˜๐—ต๐—ฒ ๐—ฆ๐˜„๐—ฒ๐—ฒ๐˜ ๐—ฆ๐—ฝ๐—ผ๐˜: ๐—” ๐— ๐—ถ๐˜…๐—ฒ๐—ฑ ๐—”๐—ฝ๐—ฝ๐—ฟ๐—ผ๐—ฎ๐—ฐ๐—ต

Combining different types of keys can offer a balanced solution:

โ€ข InternalID: Used for internal operations and relationships between tables.

โ€ข PublicID: Used in API responses and endpoints to securely reference user records.

โ€ข Email (Natural Key): Used to ensure unique identification of users within the business logic.


The mixed approach keeps your system fast, secure, and easy to understand.

Here you can find essential SQL Interview Resources๐Ÿ‘‡
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v

Like this post if you need more ๐Ÿ‘โค๏ธ

Hope it helps :)
๐Ÿ‘4โค2
SQL Query Logical Order
โค10๐Ÿ‘1
How a SQL query gets executed internally - Lets see step by step!

We all know SQL, but most of us do not understand the internals of it.

Let me take an example to explain this better.

Select p.plan_name, count(plan_id) as total_count
From plans p
Join subscriptions s on s.plan_id=p.plan_id
Where p.plan_name !=โ€™premiumโ€™
Group by p.plan_name
Having count(plan_id) > 100
Order by p.plan_name
Limit 10;

Step 01: Get the table data required to run the sql query
Operations: FROM, JOIN (From plans p, Join subscriptions s)

Step 02: Filter the data rows
Operations: WHERE (where p.plan_name=โ€™premiumโ€™)

Step 03: Group the data
Operations: GROUP (group by p.plan_name)

Step 04: Filter the grouped data
Operations: HAVING (having count(plan_id) > 100)

Step 05: Select the data columns
Operations: SELECT (select p.plan_name, count(p.plan_id)

Step 06: Order the data
Operations: ORDER BY (order by p.plan_name)

Step 07: Limit the data rows
Operations: LIMIT (limit 100)

Knowing the Internals really help.

Here you can find essential SQL Interview Resources๐Ÿ‘‡
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v

Like this post if you need answer for the above question๐Ÿ‘โค๏ธ

Hope it helps :)
โค2๐Ÿ‘2
SQL for Data Analysis

Most people learn SQL just enough to pull some data. But if you really understand it, you can analyze massive datasets without touching Excel or Python.

Here are 8 game-changing SQL concepts that will make you a data pro:

๐Ÿ‘‡


1. Stop pulling raw data. Start pulling insights.

The biggest mistake? Running a query that gives you everything and then filtering it later.

Good analysts donโ€™t pull raw data. They shape the data before it even reaches them.

2. โ€œSELECT โ€ is a rookie move.

Pulling all columns is lazy and slow.

A pro only selects what they need.
โœ”๏ธ Fewer columns = Faster queries
โœ”๏ธ Less noise = Clearer insights

The more precise your query, the less time you waste cleaning data.

3. GROUP BY is your best friend.

You donโ€™t need 100,000 rows of transactions. What you need is:
โœ”๏ธ Sales per region
โœ”๏ธ Average order size per customer
โœ”๏ธ Number of signups per month

Grouping turns chaotic data into useful summaries.

4. Joins = Connecting the dots.

Your most important data is split across multiple tables.

Want to know how much each customer spent? You need to join:
โœ”๏ธ Customer info
โœ”๏ธ Order history
โœ”๏ธ Payments

Joins = unlocking hidden insights.

5. Window functions will blow your mind.

They let you:
โœ”๏ธ Rank customers by total purchases
โœ”๏ธ Calculate rolling averages
โœ”๏ธ Compare each row to the overall trend

Itโ€™s like pivot tables, but way more powerful.

6. CTEs will save you from spaghetti SQL.

Instead of writing a 50-line nested query, break it into steps.

CTEs (Common Table Expressions) make your SQL:
โœ”๏ธ Easier to read
โœ”๏ธ Easier to debug
โœ”๏ธ Reusable

Good SQL is clean SQL.

7. Indexes = Speed.

If your queries take forever, your database is probably doing unnecessary work.

Indexes help databases find data faster.

If you work with large datasets, this is a game changer.

SQL isnโ€™t just about pulling data. Itโ€™s about analyzing, transforming, and optimizing it.

Master these 8 concepts, and youโ€™ll never look at SQL the same way again.

Join us on WhatsApp: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
โค3๐Ÿ‘3
Top Tools to learn Data Engineering

Join for more data engineering resources: https://t.iss.one/sql_engineer
โค2๐Ÿ‘2
๐Ÿ˜‚๐Ÿ˜‚
๐Ÿคฃ20๐Ÿค”3
The way you WRITE an SQL query differs from the way SQL PROCESSES it DataAnalytics

Your query might look like this:

1. SELECT
2. FROM
3. WHERE
4. GROUP BY
5. HAVING
6. ORDER BY

But SQL executes queries in a different order:

FROM (identifies table)
WHERE (filters rows)
GROUP BY (groups rows)
HAVING (filters grouped rows)
SELECT (chooses columns to display)
ORDER BY (sorts final output)
โค14๐Ÿ‘8๐ŸŽ‰1
Why SQL is a Must-Have Skill?

If you're working with data, mastering SQL is non-negotiable! Itโ€™s the backbone of handling and making sense of vast datasets in any industry.

โ—† Data at Your Fingertips
Effortlessly organize, retrieve, and manage large datasets to make informed decisions faster.

โ—† Stay Organized
Use primary and foreign keys to keep your data accurate and connected across tables.

โ—† Unlock Insights
Combine data from multiple sources and uncover trends using SQL's powerful query capabilities.

โ—† Efficiency Matters
Optimize your databases with normalization and avoid unnecessary redundancy.

โ—† Advanced Tools
From ACID transactions to optimizing with DELETE vs TRUNCATE, SQL makes sure your data is consistent and secure.

Here you can find essential SQL Interview Resources๐Ÿ‘‡
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v

Like this post if you need more ๐Ÿ‘โค๏ธ

Hope it helps :)
๐Ÿ‘4โค1
SQL Zero to Hero ๐Ÿ’ช
โค5๐Ÿ‘1
SQL From Basic to Advanced level

Basic SQL is ONLY 7 commands:
- SELECT
- FROM
- WHERE (also use SQL comparison operators such as =, <=, >=, <> etc.)
- ORDER BY
- Aggregate functions such as SUM, AVERAGE, COUNT etc.
- GROUP BY
- CREATE, INSERT, DELETE, etc.
You can do all this in just one morning.

Once you know these, take the next step and learn commands like:
- LEFT JOIN
- INNER JOIN
- LIKE
- IN
- CASE WHEN
- HAVING (undertstand how it's different from GROUP BY)
- UNION ALL
This should take another day.

Once both basic and intermediate are done, start learning more advanced SQL concepts such as:
- Subqueries (when to use subqueries vs CTE?)
- CTEs (WITH AS)
- Stored Procedures
- Triggers
- Window functions (LEAD, LAG, PARTITION BY, RANK, DENSE RANK)
These can be done in a couple of days.
Learning these concepts is NOT hard at all

- what takes time is practice and knowing what command to use when. How do you master that?
- First, create a basic SQL project
- Then, work on an intermediate SQL project (search online) -

Lastly, create something advanced on SQL with many CTEs, subqueries, stored procedures and triggers etc.

This is ALL you need to become a badass in SQL, and trust me when I say this, it is not rocket science. It's just logic.

Remember that practice is the key here. It will be more clear and perfect with the continous practice

SQL Interview Resources๐Ÿ‘‡
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v

Like this post if you need more ๐Ÿ‘โค๏ธ

Hope it helps :)
๐Ÿ‘8โค7๐Ÿ˜1
5 frequently Asked SQL Interview Questions with Answers in Data Engineering interviews:
๐ƒ๐ข๐Ÿ๐Ÿ๐ข๐œ๐ฎ๐ฅ๐ญ๐ฒ - ๐Œ๐ž๐๐ข๐ฎ๐ฆ

โšซ๏ธDetermine the Top 5 Products with the Highest Revenue in Each Category.
Schema: Products (ProductID, Name, CategoryID), Sales (SaleID, ProductID, Amount)

WITH ProductRevenue AS (
SELECT p.ProductID,
p.Name,
p.CategoryID,
SUM(s.Amount) AS TotalRevenue,
RANK() OVER (PARTITION BY p.CategoryID ORDER BY SUM(s.Amount) DESC) AS RevenueRank
FROM Products p
JOIN Sales s ON p.ProductID = s.ProductID
GROUP BY p.ProductID, p.Name, p.CategoryID
)
SELECT ProductID, Name, CategoryID, TotalRevenue
FROM ProductRevenue
WHERE RevenueRank <= 5;

โšซ๏ธ Identify Employees with Increasing Sales for Four Consecutive Quarters.
Schema: Sales (EmployeeID, SaleDate, Amount)

WITH QuarterlySales AS (
SELECT EmployeeID,
DATE_TRUNC('quarter', SaleDate) AS Quarter,
SUM(Amount) AS QuarterlyAmount
FROM Sales
GROUP BY EmployeeID, DATE_TRUNC('quarter', SaleDate)
),
SalesTrend AS (
SELECT EmployeeID,
Quarter,
QuarterlyAmount,
LAG(QuarterlyAmount, 1) OVER (PARTITION BY EmployeeID ORDER BY Quarter) AS PrevQuarter1,
LAG(QuarterlyAmount, 2) OVER (PARTITION BY EmployeeID ORDER BY Quarter) AS PrevQuarter2,
LAG(QuarterlyAmount, 3) OVER (PARTITION BY EmployeeID ORDER BY Quarter) AS PrevQuarter3
FROM QuarterlySales
)
SELECT EmployeeID, Quarter, QuarterlyAmount
FROM SalesTrend
WHERE QuarterlyAmount > PrevQuarter1 AND PrevQuarter1 > PrevQuarter2 AND PrevQuarter2 > PrevQuarter3;

โšซ๏ธ List Customers Who Made Purchases in Each of the Last Three Years.
Schema: Orders (OrderID, CustomerID, OrderDate)

WITH YearlyOrders AS (
SELECT CustomerID,
EXTRACT(YEAR FROM OrderDate) AS OrderYear
FROM Orders
GROUP BY CustomerID, EXTRACT(YEAR FROM OrderDate)
),
RecentYears AS (
SELECT DISTINCT OrderYear
FROM Orders
WHERE OrderDate >= CURRENT_DATE - INTERVAL '3 years'
),
CustomerYearlyOrders AS (
SELECT CustomerID,
COUNT(DISTINCT OrderYear) AS YearCount
FROM YearlyOrders
WHERE OrderYear IN (SELECT OrderYear FROM RecentYears)
GROUP BY CustomerID
)
SELECT CustomerID
FROM CustomerYearlyOrders
WHERE YearCount = 3;


โšซ๏ธ Find the Third Lowest Price for Each Product Category.
Schema: Products (ProductID, Name, CategoryID, Price)

WITH RankedPrices AS (
SELECT CategoryID,
Price,
DENSE_RANK() OVER (PARTITION BY CategoryID ORDER BY Price ASC) AS PriceRank
FROM Products
)
SELECT CategoryID, Price
FROM RankedPrices
WHERE PriceRank = 3;

โšซ๏ธ Identify Products with Total Sales Exceeding a Specified Threshold Over the Last 30 Days.
Schema: Sales (SaleID, ProductID, SaleDate, Amount)

WITH RecentSales AS (
SELECT ProductID,
SUM(Amount) AS TotalSales
FROM Sales
WHERE SaleDate >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY ProductID
)
SELECT ProductID, TotalSales
FROM RecentSales
WHERE TotalSales > 200;

Here you can find essential SQL Interview Resources๐Ÿ‘‡
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v

Like this post if you need more ๐Ÿ‘โค๏ธ

Hope it helps :)
๐Ÿ‘9โค1
Types Of Databases
๐Ÿ‘5๐Ÿ‘1
Why SQL Query Optimization Matters More Than You Think

Have you ever noticed your SQL queries dragging their feet, taking forever to return results? Itโ€™s frustrating, right? The truth is that optimizing your SQL queries is essential if you want your applications to run smoothly and efficiently.

Hereโ€™s why SQL optimization should be on your radar:

โ†’ ๐—ฆ๐—ฝ๐—ฒ๐—ฒ๐—ฑ ๐— ๐—ฎ๐˜๐˜๐—ฒ๐—ฟ๐˜€: Did you know that optimized SQL queries can run up to 10 times faster? That means getting the data you need in seconds instead of minutes. Imagine how much more you could get done with that kind of speed!

โ†’ ๐—ฆ๐—ฎ๐˜ƒ๐—ฒ ๐—ผ๐—ป ๐—–๐—ผ๐˜€๐˜๐˜€: Every second your query runs, itโ€™s using up resources like CPU and memory. By optimizing your queries, you can cut down on resource usage, which can save you a lot of moneyโ€”especially if youโ€™re working in the cloud where every bit of processing power is billed.

โ†’ ๐—ฆ๐˜๐—ฎ๐˜† ๐—ฆ๐—ฐ๐—ฎ๐—น๐—ฎ๐—ฏ๐—น๐—ฒ: Your data isnโ€™t getting any smaller, and as it grows, so does the load on your database. Optimization ensures that as your datasets grow, your queries can handle the increased workload without slowing down. This is crucial if you want to keep everything running smoothly as your business scales.

โ†’ ๐—›๐—ฎ๐—ฝ๐—ฝ๐˜† ๐—จ๐˜€๐—ฒ๐—ฟ๐˜€: No one likes waiting, especially not your users. Faster queries mean a better experience for everyone. When your application is responsive, it keeps users engaged and happy, which is a big win.

๐—›๐—ฒ๐—ฟ๐—ฒโ€™๐˜€ ๐˜๐—ต๐—ฒ ๐—ถ๐—บ๐—ฝ๐—ฎ๐—ฐ๐˜ ๐—ผ๐—ณ ๐—ด๐—ฒ๐˜๐˜๐—ถ๐—ป๐—ด ๐—ถ๐˜ ๐—ฟ๐—ถ๐—ด๐—ต๐˜:

โ†’ Businesses that focus on optimizing their SQL queries often see a 30-50% improvement in application performance.

โ†’ By just tweaking the slowest 10% of your queries, you can slash your database resource usage by up to 50%.

โ†’ Proper indexing and smart query design can turn minutes into seconds, which is a game-changer for user satisfaction and productivity.

Here you can find essential SQL Interview Resources๐Ÿ‘‡
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v

Like this post if you need more ๐Ÿ‘โค๏ธ

Hope it helps :)
๐Ÿ‘6โค1๐ŸŽ‰1
How to optimize SQL code:

๐Ÿญ) ๐—ข๐—ป๐—น๐˜† ๐˜€๐—ฒ๐—น๐—ฒ๐—ฐ๐˜ ๐˜๐—ต๐—ฒ ๐—ป๐—ฒ๐—ฐ๐—ฒ๐˜€๐˜€๐—ฎ๐—ฟ๐˜† ๐—ฐ๐—ผ๐—น๐˜‚๐—บ๐—ป๐˜€

This tip is specially important when you work with large tables, running window functions, or multiple joins.

DON'T: Select all the columns from the table
DOs: Select only the columns you need!

๐Ÿฎ) ๐—”๐—น๐˜„๐—ฎ๐˜†๐˜€ ๐—ณ๐—ถ๐—น๐˜๐—ฒ๐—ฟ ๐—ฎ๐˜€ ๐˜€๐—ผ๐—ผ๐—ป ๐—ฎ๐˜€ ๐˜†๐—ผ๐˜‚ ๐—ฐ๐—ฎ๐—ป

If you only need certain rows from a table, apply the filters as early as you can.

Please, don't wait until you do all the CTEs, then all the joins, and realize you need to apply some filtersโ€ฆ Your company will thank you for that.

๐Ÿฏ) ๐—๐—ผ๐—ถ๐—ป ๐˜†๐—ผ๐˜‚๐—ฟ ๐—น๐—ฎ๐—ฟ๐—ด๐—ฒ๐˜€๐˜ ๐˜๐—ฎ๐—ฏ๐—น๐—ฒ ๐—ฎ๐˜ ๐˜๐—ต๐—ฒ ๐—ฒ๐—ป๐—ฑ (๐—ถ๐—ณ ๐˜†๐—ผ๐˜‚ ๐—ฐ๐—ฎ๐—ป!)

We've all experienced it. But when you have your biggest table as the base, and joining it to other tables it will result in a lot of scanning.

Look at these 2 queries:

๐Ÿญ) ๐—ฆ๐—˜๐—Ÿ๐—˜๐—–๐—ง * ๐—™๐—ฅ๐—ข๐—  ๐—ฏ๐—ถ๐—ด_๐˜๐—ฎ๐—ฏ๐—น๐—ฒ ๐—œ๐—ก๐—ก๐—˜๐—ฅ ๐—๐—ข๐—œ๐—ก ๐˜๐—ฎ๐—ฏ๐—น๐—ฒ_๐Ÿญ ๐—ข๐—ก ๐˜…๐˜…๐˜…

vs.

๐Ÿฎ) ๐—ฆ๐—˜๐—Ÿ๐—˜๐—–๐—ง * ๐—™๐—ฅ๐—ข๐—  ๐˜๐—ฎ๐—ฏ๐—น๐—ฒ_๐Ÿญ ๐—œ๐—ก๐—ก๐—˜๐—ฅ ๐—๐—ข๐—œ๐—ก ๐—ฏ๐—ถ๐—ด_๐˜๐—ฎ๐—ฏ๐—น๐—ฒ ๐—ข๐—ก ๐˜…๐˜…๐˜…

The second query will be significantly lower in computing power, so make sure to always start with the smallest table as you base (the best you can!)

๐Ÿฐ) ๐—•๐—ฒ ๐—š๐—ฒ๐—ป๐˜๐—น๐—ฒ ๐˜„๐—ถ๐˜๐—ต ๐˜„๐—ถ๐—ป๐—ฑ๐—ผ๐˜„ ๐—ณ๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€

I've seen many people saying use window function for your queries. Well, I don't think it's a good idea.

Yes, they are powerful but they are also resource-intensive, so use them only if necessary.

And ask yourself how much data it needs to process!

๐Ÿฑ) ๐— ๐—ผ๐—ฟ๐—ฒ ๐—–๐—ง๐—˜๐˜€ ๐—น๐—ฒ๐˜€๐˜€ ๐˜€๐˜‚๐—ฏ๐—พ๐˜‚๐—ฒ๐—ฟ๐—ถ๐—ฒ๐˜€

Think about your audience. When you are writing a huge query with sub-queries, it is (very!) hard for people to navigate.

Think of replacing them with CTE - they will thank you for that!
And it will also be easier for you to debug and optimize (if needed)

Here you can find essential SQL Interview Resources๐Ÿ‘‡
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v

Like this post if you need more ๐Ÿ‘โค๏ธ

Hope it helps :)
๐Ÿ‘5โค1