SQL Programming Resources
75.8K subscribers
505 photos
13 files
446 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
Forwarded from Data Analytics
Which of the following is SQL Command is used to sort results?
Anonymous Quiz
34%
SORT BY
57%
ORDER BY
7%
SORTED
3%
ORDER ON
๐Ÿ‘5
Many people pay too much to learn SQL, but my mission is to break down barriers. I have shared complete learning series to learn SQL from scratch.

Here are the links to the SQL series

Complete SQL Topics for Data Analyst: https://t.iss.one/sqlspecialist/523

Part-1: https://t.iss.one/sqlspecialist/524

Part-2: https://t.iss.one/sqlspecialist/525

Part-3: https://t.iss.one/sqlspecialist/526

Part-4: https://t.iss.one/sqlspecialist/527

Part-5: https://t.iss.one/sqlspecialist/529

Part-6: https://t.iss.one/sqlspecialist/534

Part-7: https://t.iss.one/sqlspecialist/534

Part-8: https://t.iss.one/sqlspecialist/536

Part-9: https://t.iss.one/sqlspecialist/537

Part-10: https://t.iss.one/sqlspecialist/539

Part-11: https://t.iss.one/sqlspecialist/540

Part-12:
https://t.iss.one/sqlspecialist/541

Part-13: https://t.iss.one/sqlspecialist/542

Part-14: https://t.iss.one/sqlspecialist/544

Part-15: https://t.iss.one/sqlspecialist/545

Part-16: https://t.iss.one/sqlspecialist/546

Part-17: https://t.iss.one/sqlspecialist/549

Part-18: https://t.iss.one/sqlspecialist/552

Part-19: https://t.iss.one/sqlspecialist/555

Part-20: https://t.iss.one/sqlspecialist/556

I saw a lot of big influencers copy pasting my content after removing the credits. It's absolutely fine for me as more people are getting free education because of my content.

But I will really appreciate if you share credits for the time and efforts I put in to create such valuable content. I hope you can understand.

Complete Python Topics for Data Analysts: https://t.iss.one/sqlspecialist/548

Complete Excel Topics for Data Analysts: https://t.iss.one/sqlspecialist/547

I'll continue with learning series on Python, Power BI, Excel & Tableau.

Thanks to all who support our channel and share the content with proper credits. You guys are really amazing.

Hope it helps :)
โค9๐Ÿ‘4๐Ÿ‘3
โœ๏ธBest practices for writing SQL ๐Ÿ“Šqueries:

1- Write SQL keywords in capital letters.

2- Use table aliases with columns when you are joining multiple tables.

3- Never use select *, always mention list of columns in select clause.

4- Add useful comments wherever you write complex logic. Avoid too many comments.

5- Use joins instead of subqueries when possible for better performance.

6- Create CTEs instead of multiple sub queries , it will make your query easy to read.

7- Join tables using JOIN keywords instead of writing join condition in where clause for better readability.

8- Never use order by in sub queries , It will unnecessary increase runtime.

9- If you know there are no duplicates in 2 tables, use UNION ALL instead of UNION for better performance.

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

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

Hope it helps :)
๐Ÿ‘7โค2
SQL Basics for Beginners: Must-Know Concepts

1. What is SQL? 
   SQL (Structured Query Language) is a standard language used to communicate with databases. It allows you to query, update, and manage relational databases by writing simple or complex queries.

2. SQL Syntax 
   SQL is written using statements, which consist of keywords like SELECT, FROM, WHERE, etc., to perform operations on the data.
   - SQL keywords are not case-sensitive, but it's common to write them in uppercase (e.g., SELECT, FROM).

3. SQL Data Types 
   Databases store data in different formats. The most common data types are:
   - INT (Integer): For whole numbers.
   - VARCHAR(n) or TEXT: For storing text data.
   - DATE: For dates.
   - DECIMAL: For precise decimal values, often used in financial calculations.

4. Basic SQL Queries 
   Here are some fundamental SQL operations:

   - SELECT Statement: Used to retrieve data from a database.
   
     SELECT column1, column2 FROM table_name;
    

   - WHERE Clause: Filters data based on conditions.
   
     SELECT * FROM table_name WHERE condition;
    

   - ORDER BY: Sorts data in ascending (ASC) or descending (DESC) order.
   
     SELECT column1, column2 FROM table_name ORDER BY column1 ASC;
    

   - LIMIT: Limits the number of rows returned.
   
     SELECT * FROM table_name LIMIT 5;
    

5. Filtering Data with WHERE Clause 
   The WHERE clause helps you filter data based on a condition:
 
   SELECT * FROM employees WHERE salary > 50000;
  

   You can use comparison operators like:
   - =: Equal to
   - >: Greater than
   - <: Less than
   - LIKE: For pattern matching

6. Aggregating Data 
   SQL provides functions to summarize or aggregate data:
   - COUNT(): Counts the number of rows.
   
     SELECT COUNT(*) FROM table_name;
    

   - SUM(): Adds up values in a column.
   
     SELECT SUM(salary) FROM employees;
    

   - AVG(): Calculates the average value.
   
     SELECT AVG(salary) FROM employees;
    

   - GROUP BY: Groups rows that have the same values into summary rows.
   
     SELECT department, AVG(salary) FROM employees GROUP BY department;
    

7. Joins in SQL 
   Joins combine data from two or more tables:
   - INNER JOIN: Retrieves records with matching values in both tables.
   
     SELECT employees.name, departments.department
     FROM employees
     INNER JOIN departments
     ON employees.department_id = departments.id;
    

   - LEFT JOIN: Retrieves all records from the left table and matched records from the right table.
   
     SELECT employees.name, departments.department
     FROM employees
     LEFT JOIN departments
     ON employees.department_id = departments.id;
    

8. Inserting Data
   To add new data to a table, you use the INSERT INTO statement:
 
   INSERT INTO employees (name, position, salary) VALUES ('John Doe', 'Analyst', 60000);
  

9. Updating Data
   You can update existing data in a table using the UPDATE statement:
 
   UPDATE employees SET salary = 65000 WHERE name = 'John Doe';
  

10. Deleting Data
    To remove data from a table, use the DELETE statement:
  
    DELETE FROM employees WHERE name = 'John Doe';
   


Hope it helps :)
๐Ÿ‘12โค10
๐Ÿ˜‚๐Ÿ˜‚
๐Ÿคฃ15โค5
SQL Programming Resources
๐Ÿ˜‚๐Ÿ˜‚
Jokes apart, if you really want to improve your communication skills, you should definitely join @englishlearnerspro
โค2๐Ÿ‘2
๐Ÿฑ ๐—ฆ๐—ค๐—Ÿ ๐— ๐˜†๐˜๐—ต๐˜€ ๐——๐—ฒ๐—ฏ๐˜‚๐—ป๐—ธ๐—ฒ๐—ฑ โŒ ๐—ช๐—ต๐—ฎ๐˜ ๐—•๐—ฒ๐—ด๐—ถ๐—ป๐—ป๐—ฒ๐—ฟ๐˜€ ๐—ข๐—ณ๐˜๐—ฒ๐—ป ๐—š๐—ฒ๐˜ ๐—ช๐—ฟ๐—ผ๐—ป๐—ด

SQL is super powerful, but some myths around it can trip up beginners.

Letโ€™s clear up five common misunderstandings and set the record straight:

๐— ๐˜†๐˜๐—ต ๐Ÿญ: ๐—ฆ๐—ค๐—Ÿ ๐—ถ๐˜€ ๐—ท๐˜‚๐˜€๐˜ ๐—ณ๐—ผ๐—ฟ ๐—ฝ๐˜‚๐—น๐—น๐—ถ๐—ป๐—ด ๐—ฑ๐—ฎ๐˜๐—ฎ.

โœฆ ๐—ฅ๐—ฒ๐—ฎ๐—น๐—ถ๐˜๐˜†: Nope, itโ€™s not just for that! SQL can also create, modify, and manage databases, control access, and maintain data consistency.

โœฆ ๐—™๐—ถ๐˜… ๐—ถ๐˜: Explore all the features of SQL, like DDL (for database design), DCL (for access control), and TCL (for transactions). It's more than just SELECT!

๐— ๐˜†๐˜๐—ต ๐Ÿฎ: ๐—จ๐˜€๐—ถ๐—ป๐—ด ๐—ฆ๐—˜๐—Ÿ๐—˜๐—–๐—ง *  ๐—ถ๐˜€ ๐—ณ๐—ถ๐—ป๐—ฒ.

โœฆ ๐—ฅ๐—ฒ๐—ฎ๐—น๐—ถ๐˜๐˜†: It might be easy, but itโ€™s not efficient. Pulling all columns wastes memory and slows down performance.

โœฆ ๐—™๐—ถ๐˜… ๐—ถ๐˜: Only select the columns you actually need. Itโ€™s faster and cleaner.
Not great - SELECT * FROM employees;
Better - SELECT employee_id, name, department FROM employees;

๐— ๐˜†๐˜๐—ต ๐Ÿฏ: ๐—ฆ๐—ค๐—Ÿ ๐—ฐ๐—ฎ๐—ป'๐˜ ๐—ต๐—ฎ๐—ป๐—ฑ๐—น๐—ฒ ๐—ฐ๐—ผ๐—บ๐—ฝ๐—น๐—ฒ๐˜… ๐—ฎ๐—ป๐—ฎ๐—น๐˜†๐˜€๐—ถ๐˜€.

โœฆ ๐—ฅ๐—ฒ๐—ฎ๐—น๐—ถ๐˜๐˜†: SQL can do way more than basic queries! With concepts like window functions and CTEs, you can handle really complex data analysis.

โœฆ ๐—™๐—ถ๐˜… ๐—ถ๐˜: Learn advanced SQL features like window functions (ROW_NUMBER(), RANK()) and CTEs to up your game.
Example - Ranking employees by salary within their department


WITH ranked_salaries AS (SELECT employee_id, salary, department,
ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) AS rank FROM employees)
SELECT * FROM ranked_salaries WHERE rank = 1;


๐— ๐˜†๐˜๐—ต ๐Ÿฐ: ๐—ฆ๐—น๐—ผ๐˜„ ๐—พ๐˜‚๐—ฒ๐—ฟ๐—ถ๐—ฒ๐˜€ ๐—ฎ๐—ฟ๐—ฒ ๐—ฎ๐—น๐˜„๐—ฎ๐˜†๐˜€ ๐˜๐—ต๐—ฒ ๐—ฑ๐—ฎ๐˜๐—ฎ๐—ฏ๐—ฎ๐˜€๐—ฒโ€™๐˜€ ๐—ณ๐—ฎ๐˜‚๐—น๐˜.

โœฆ ๐—ฅ๐—ฒ๐—ฎ๐—น๐—ถ๐˜๐˜†: Itโ€™s usually inefficient queries causing the slowdown. Things like missing indexes or unoptimized code can be the culprit.

โœฆ ๐—™๐—ถ๐˜… ๐—ถ๐˜: Use indexes properly, avoid complex calculations in WHERE clauses, and check your query execution plan to spot bottlenecks.

๐— ๐˜†๐˜๐—ต ๐Ÿฑ: ๐—ฆ๐—ค๐—Ÿ ๐—ถ๐˜€ ๐—ผ๐˜‚๐˜๐—ฑ๐—ฎ๐˜๐—ฒ๐—ฑ ๐—ฎ๐—ป๐—ฑ ๐˜„๐—ถ๐—น๐—น ๐—ฏ๐—ฒ ๐—ฟ๐—ฒ๐—ฝ๐—น๐—ฎ๐—ฐ๐—ฒ๐—ฑ ๐˜€๐—ผ๐—ผ๐—ป.

โœฆ ๐—ฅ๐—ฒ๐—ฎ๐—น๐—ถ๐˜๐˜†: SQL is here to stay! Despite the rise of NoSQL, SQL remains the backbone for structured data.

โœฆ ๐—™๐—ถ๐˜… ๐—ถ๐˜: Stay current and explore how SQL integrates with big data platforms and cloud databases. Itโ€™s more relevant than ever.

Donโ€™t let these myths hold you back. SQL is powerful, and when you understand it fully, you can do amazing things with your data.

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

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

Hope it helps :)
๐Ÿ‘8โค1
Most Asked SQL Interview Questions at MAANG Companies๐Ÿ”ฅ๐Ÿ”ฅ

Preparing for an SQL Interview at MAANG Companies? Here are some crucial SQL Questions you should be ready to tackle:

1. How do you retrieve all columns from a table?

SELECT * FROM table_name;

2. What SQL statement is used to filter records?

SELECT * FROM table_name
WHERE condition;

The WHERE clause is used to filter records based on a specified condition.

3. How can you join multiple tables? Describe different types of JOINs.

SELECT columns
FROM table1
JOIN table2 ON table1.column = table2.column
JOIN table3 ON table2.column = table3.column;

Types of JOINs:

1. INNER JOIN: Returns records with matching values in both tables

SELECT * FROM table1
INNER JOIN table2 ON table1.column = table2.column;

2. LEFT JOIN: Returns all records from the left table & matched records from the right table. Unmatched records will have NULL values.

SELECT * FROM table1
LEFT JOIN table2 ON table1.column = table2.column;

3. RIGHT JOIN: Returns all records from the right table & matched records from the left table. Unmatched records will have NULL values.

SELECT * FROM table1
RIGHT JOIN table2 ON table1.column = table2.column;

4. FULL JOIN: Returns records when there is a match in either left or right table. Unmatched records will have NULL values.

SELECT * FROM table1
FULL JOIN table2 ON table1.column = table2.column;

4. What is the difference between WHERE & HAVING clauses?

WHERE: Filters records before any groupings are made.

SELECT * FROM table_name
WHERE condition;

HAVING: Filters records after groupings are made.

SELECT column, COUNT(*)
FROM table_name
GROUP BY column
HAVING COUNT(*) > value;

5. How do you calculate average, sum, minimum & maximum values in a column?

Average: SELECT AVG(column_name) FROM table_name;

Sum: SELECT SUM(column_name) FROM table_name;

Minimum: SELECT MIN(column_name) FROM table_name;

Maximum: SELECT MAX(column_name) FROM table_name;

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

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

Hope it helps :)
๐Ÿ‘8๐Ÿ‘2โค1
SQL, or Structured Query Language, is a domain-specific language used to manage and manipulate relational databases. Here's a brief A-Z overview by @sqlanalyst

A - Aggregate Functions: Functions like COUNT, SUM, AVG, MIN, and MAX used to perform operations on data in a database.

B - BETWEEN: A SQL operator used to filter results within a specific range.

C - CREATE TABLE: SQL statement for creating a new table in a database.

D - DELETE: SQL statement used to delete records from a table.

E - EXISTS: SQL operator used in a subquery to test if a specified condition exists.

F - FOREIGN KEY: A field in a database table that is a primary key in another table, establishing a link between the two tables.

G - GROUP BY: SQL clause used to group rows that have the same values in specified columns.

H - HAVING: SQL clause used in combination with GROUP BY to filter the results.

I - INNER JOIN: SQL clause used to combine rows from two or more tables based on a related column between them.

J - JOIN: Combines rows from two or more tables based on a related column.

K - KEY: A field or set of fields in a database table that uniquely identifies each record.

L - LIKE: SQL operator used in a WHERE clause to search for a specified pattern in a column.

M - MODIFY: SQL command used to modify an existing database table.

N - NULL: Represents missing or undefined data in a database.

O - ORDER BY: SQL clause used to sort the result set in ascending or descending order.

P - PRIMARY KEY: A field in a table that uniquely identifies each record in that table.

Q - QUERY: A request for data from a database using SQL.

R - ROLLBACK: SQL command used to undo transactions that have not been saved to the database.

S - SELECT: SQL statement used to query the database and retrieve data.

T - TRUNCATE: SQL command used to delete all records from a table without logging individual row deletions.

U - UPDATE: SQL statement used to modify the existing records in a table.

V - VIEW: A virtual table based on the result of a SELECT query.

W - WHERE: SQL clause used to filter the results of a query based on a specified condition.

X - (E)XISTS: Used in conjunction with SELECT to test the existence of rows returned by a subquery.

Z - ZERO: Represents the absence of a value in numeric fields or the initial state of boolean fields.

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

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

Hope it helps :)
โค5๐Ÿ‘5
SQL Interview Questions !!

๐ŸŽ— Write a query to find all employees whose salaries exceed the company's average salary.
๐ŸŽ— Write a query to retrieve the names of employees who work in the same department as 'John Doe'.
๐ŸŽ— Write a query to display the second highest salary from the Employee table without using the MAX function twice.
๐ŸŽ— Write a query to find all customers who have placed more than five orders.
๐ŸŽ— Write a query to count the total number of orders placed by each customer.
๐ŸŽ— Write a query to list employees who joined the company within the last 6 months.
๐ŸŽ— Write a query to calculate the total sales amount for each product.
๐ŸŽ— Write a query to list all products that have never been sold.
๐ŸŽ— Write a query to remove duplicate rows from a table.
๐ŸŽ— Write a query to identify the top 10 customers who have not placed any orders in the past year.
๐Ÿ‘7
SQL Learning plan in 2025

|-- Week 1: Introduction to SQL
|   |-- SQL Basics
|   |   |-- What is SQL?
|   |   |-- History and Evolution of SQL
|   |   |-- Relational Databases
|   |-- Setting up for SQL
|   |   |-- Installing MySQL/PostgreSQL
|   |   |-- Setting up a Database
|   |   |-- Basic SQL Syntax
|   |-- First SQL Queries
|   |   |-- SELECT Statements
|   |   |-- WHERE Clauses
|   |   |-- Basic Filtering
|
|-- Week 2: Intermediate SQL
|   |-- Advanced SELECT Queries
|   |   |-- ORDER BY
|   |   |-- LIMIT
|   |   |-- Aliases
|   |-- Joining Tables
|   |   |-- INNER JOIN
|   |   |-- LEFT JOIN
|   |   |-- RIGHT JOIN
|   |   |-- FULL OUTER JOIN
|   |-- Aggregations
|   |   |-- COUNT, SUM, AVG, MIN, MAX
|   |   |-- GROUP BY
|   |   |-- HAVING Clauses
|
|-- Week 3: Advanced SQL Techniques
|   |-- Subqueries
|   |   |-- Basic Subqueries
|   |   |-- Correlated Subqueries
|   |-- Window Functions
|   |   |-- ROW_NUMBER, RANK, DENSE_RANK
|   |   |-- NTILE, LEAD, LAG
|   |-- Advanced Joins
|   |   |-- Self Joins
|   |   |-- Cross Joins
|   |-- Data Types and Functions
|   |   |-- Date Functions
|   |   |-- String Functions
|   |   |-- Numeric Functions
|
|-- Week 4: Database Design and Normalization
|   |-- Database Design Principles
|   |   |-- ER Diagrams
|   |   |-- Relationships and Cardinality
|   |-- Normalization
|   |   |-- First Normal Form (1NF)
|   |   |-- Second Normal Form (2NF)
|   |   |-- Third Normal Form (3NF)
|   |-- Indexes and Performance Tuning
|   |   |-- Creating Indexes
|   |   |-- Understanding Execution Plans
|   |   |-- Optimizing Queries
|
|-- Week 5: Stored Procedures and Functions
|   |-- Stored Procedures
|   |   |-- Creating Stored Procedures
|   |   |-- Parameters in Stored Procedures
|   |   |-- Error Handling
|   |-- Functions
|   |   |-- Scalar Functions
|   |   |-- Table-Valued Functions
|   |   |-- System Functions
|
|-- Week 6: Transactions and Concurrency
|   |-- Transactions
|   |   |-- ACID Properties
|   |   |-- COMMIT and ROLLBACK
|   |   |-- Savepoints
|   |-- Concurrency Control
|   |   |-- Locking Mechanisms
|   |   |-- Isolation Levels
|   |   |-- Deadlocks and How to Avoid Them
|
|-- Week 7-8: Advanced SQL Topics
|   |-- Triggers
|   |   |-- Creating and Using Triggers
|   |   |-- AFTER and BEFORE Triggers
|   |   |-- INSTEAD OF Triggers
|   |-- Views
|   |   |-- Creating Views
|   |   |-- Updating Views
|   |   |-- Indexed Views
|   |-- Security
|   |   |-- User Management
|   |   |-- Roles and Permissions
|   |   |-- SQL Injection Prevention
|
|-- Week 9-11: Real-world Applications and Projects
|   |-- Capstone Project
|   |   |-- Designing a Database Schema
|   |   |-- Implementing the Schema
|   |   |-- Writing Complex Queries
|   |   |-- Optimizing and Tuning
|   |-- ETL Processes
|   |   |-- Data Extraction
|   |   |-- Data Transformation
|   |   |-- Data Loading
|   |-- Data Analysis and Reporting
|   |   |-- Creating Reports
|   |   |-- Data Visualization with SQL
|   |   |-- Integration with BI Tools
|
|-- Week 12: Post-Project Learning
|   |-- Database Administration
|   |   |-- Backup and Restore
|   |   |-- Maintenance Plans
|   |   |-- Performance Monitoring
|   |-- SQL in the Cloud
|   |   |-- AWS RDS
|   |   |-- Google Cloud SQL
|   |   |-- Azure SQL Database
|   |-- Continuing Education
|   |   |-- Advanced SQL Topics

Free SQL Resources on WhatsApp: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v

Hope it helps :)
โค4๐Ÿ‘4๐Ÿ‘2
SQL query optimization techniques

โœ… Index Optimization

โžก๏ธ Ensure indexes are created on columns that are frequently used in 'WHERE' clauses, 'JOIN' conditions and as part of 'ORDER BY' clauses.
โžก๏ธUse composite indexes for columns that are frequently queried together.
โžก๏ธRegularly analyze and rebuild fragmented indexes.

โœ… Query Refactoring

โžก๏ธ Break complex queries into simpler subqueries or use common table expressions (CTEs).
โžก๏ธ Avoid unnecessary columns in the 'SELECT' clause to reduce the data processed.

โœ… Join Optimization

โžก๏ธ Use the appropriate type of join (INNER JOIN, LEFT JOIN, etc.) based on the requirements.
โžก๏ธ Ensure join columns are indexed to speed up the join operation.
โžก๏ธ Consider the join order, starting with the smallest table.

โœ… Use of Proper Data Types

โžก๏ธ Choose the most efficient data type for your columns to reduce storage and improve performance.
โžก๏ธ Avoid using 'SELECT *', specify only the columns you need.

โœ… Query Execution Plan Analysis

โžก๏ธ Use tools like 'EXPLAIN or 'EXPLAIN PLAN' to analyze how the database executes a query.
โžก๏ธ Look for full table scans, inefficient joins, or unnecessary sorting operations.

โœ… Temporary Tables and Materialized Views

โžก๏ธ Use temporary tables to store intermediate results that are reused multiple times in complex queries.
โžก๏ธ Use materialized views to store precomputed results of expensive queries.

โœ… Efficient Use of Subqueries and CTEs

โžก๏ธ Replace correlated subqueries with joins when possible to avoid repeated execution.
โžก๏ธ Use CTEs to improve readability and reusability, and sometimes performance, of complex queries.

โœ… Optimization of Aggregate Functions

โžก๏ธ Use indexed columns in 'GROUP BY' clauses to speed up aggregation.
โžก๏ธ Consider using window functions for complex aggregations instead of traditional 'GROUP BY'.

โœ… Avoiding Functions in Predicates

โžก๏ธ Avoid using functions on columns in the 'WHERE' clause as it can prevent the use of indexes.
โžก๏ธ Rewrite conditions to allow the use of indexes.

โœ… Parameter Sniffing and Query Caching

โžก๏ธ Be aware of parameter sniffing issues where SQL Server caches execution plans based on initial parameter values.
โžก๏ธ Use query hints or option recompile to address specific performance issues.
โžก๏ธ Take advantage of query caching mechanisms where appropriate to reuse execution plans.

๐Ÿ›  By applying these advanced techniques, you can significantly enhance the performance of your SQL queries and ensure that your database runs efficiently.

SQL WhatsApp Channel

Hope it helps :)
โค4๐Ÿ‘3๐Ÿ‘1
Complete SQL guide for Data Analytics

1. Introduction to SQL

What is SQL?

โ€ข SQL (Structured Query Language) is a domain-specific language used for managing and manipulating relational databases. It allows you to interact with data by querying, inserting, updating, and deleting records in a database.
โ€ข SQL is essential for Data Analytics because it enables analysts to retrieve and manipulate data for analysis, reporting, and decision-making.

Applications in Data Analytics

โ€ข Data Retrieval: SQL is used to pull data from databases for analysis.
โ€ข Data Transformation: SQL helps clean, aggregate, and transform data into a usable format for analysis.
โ€ข Reporting: SQL can be used to create reports by summarizing data or applying business rules.
โ€ข Data Modeling: SQL helps in preparing datasets for further analysis or machine learning.

2. SQL Basics

Data Types

SQL supports various data types that define the kind of data a column can hold:
โ€ข Numeric Data Types:
โ€ข INT: Integer numbers, e.g., 123.
โ€ข DECIMAL(p,s): Exact numbers with a specified precision and scale, e.g., DECIMAL(10,2) for numbers like 12345.67.
โ€ข FLOAT: Approximate numbers, e.g., 123.456.
โ€ข String Data Types:
โ€ข CHAR(n): Fixed-length strings, e.g., CHAR(10) will always use 10 characters.
โ€ข VARCHAR(n): Variable-length strings, e.g., VARCHAR(50) can store up to 50 characters.
โ€ข TEXT: Long text data, e.g., descriptions or long notes.
โ€ข Date/Time Data Types:
โ€ข DATE: Stores date values, e.g., 2024-12-01.
โ€ข DATETIME: Stores both date and time, e.g., 2024-12-01 12:00:00.

Creating and Modifying Tables

You can create, alter, and drop tables using SQL commands:

-- Create a table with columns for ID, name, salary, and hire date
CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(50),
salary DECIMAL(10, 2),
hire_date DATE
);

-- Alter an existing table to add a new column for department
ALTER TABLE employees ADD department VARCHAR(50);

-- Drop a table (delete it from the database)
DROP TABLE employees;


Data Insertion, Updating, and Deletion

SQL allows you to manipulate data using INSERT, UPDATE, and DELETE commands:

-- Insert a new employee record
INSERT INTO employees (id, name, salary, hire_date, department)
VALUES (1, 'Alice', 75000.00, '2022-01-15', 'HR');

-- Update the salary of employee with id 1
UPDATE employees
SET salary = 80000
WHERE id = 1;

-- Delete the employee record with id 1
DELETE FROM employees WHERE id = 1;


3. Data Retrieval

SELECT Statement

The SELECT statement is used to retrieve data from a database:

SELECT * FROM employees; -- Retrieve all columns
SELECT name, salary FROM employees; -- Retrieve specific columns


Filtering Data with WHERE

The WHERE clause filters data based on specific conditions:

SELECT * FROM employees
WHERE salary > 60000 AND department = 'HR'; -- Filter records based on salary and department


Sorting Data with ORDER BY

The ORDER BY clause sorts the result set by one or more columns:

SELECT * FROM employees
ORDER BY salary DESC; -- Sort by salary in descending order


Aliasing

You can use aliases to rename columns or tables for clarity:

SELECT name AS employee_name, salary AS monthly_salary FROM employees;

4. Aggregate Functions

Aggregate functions perform calculations on a set of values and return a single result.

Common Aggregate Functions

SELECT COUNT(*) AS total_employees, AVG(salary) AS average_salary
FROM employees; -- Count total employees and calculate the average salary


GROUP BY and HAVING

โ€ข GROUP BY is used to group rows sharing the same value in a column.
โ€ข HAVING filters groups based on aggregate conditions.

-- Find average salary by department
SELECT department, AVG(salary) AS average_salary
FROM employees
GROUP BY department;

-- Filter groups with more than 5 employees
SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;


5. Joins

Joins are used to combine rows from two or more tables based on related columns.

Types of Joins
โค2๐Ÿ‘2
โ€ข INNER JOIN: Returns rows that have matching values in both tables.

SELECT e.name, e.salary, d.department_name
FROM employees e
INNER JOIN departments d ON e.department = d.department_id;


โ€ข LEFT JOIN: Returns all rows from the left table and matched rows from the right table. If no match, returns NULL.

SELECT e.name, e.salary, d.department_name
FROM employees e
LEFT JOIN departments d ON e.department = d.department_id;


โ€ข RIGHT JOIN: Returns all rows from the right table and matched rows from the left table. If no match, returns NULL.

SELECT e.name, e.salary, d.department_name
FROM employees e
RIGHT JOIN departments d ON e.department = d.department_id;


โ€ข FULL OUTER JOIN: Returns all rows when there is a match in one of the tables.

SELECT e.name, e.salary, d.department_name
FROM employees e
FULL OUTER JOIN departments d ON e.department = d.department_id;


6. Subqueries and Nested Queries

Subqueries are queries embedded inside other queries. They can be used in the SELECT, FROM, and WHERE clauses.

Correlated Subqueries

A correlated subquery references columns from the outer query.

-- Find employees with salaries above the average salary of their department
SELECT name, salary
FROM employees e1
WHERE salary > (SELECT AVG(salary)
FROM employees e2
WHERE e1.department = e2.department);


Using Subqueries in SELECT

You can also use subqueries in the SELECT statement:

SELECT name,
(SELECT AVG(salary) FROM employees) AS avg_salary
FROM employees;


7. Advanced SQL

Window Functions

Window functions perform calculations across a set of table rows related to the current row. They do not collapse rows like GROUP BY.

-- Rank employees by salary within each department
SELECT name, department, salary,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rank
FROM employees;


Common Table Expressions (CTEs)

A CTE is a temporary result set that can be referenced within a SELECT, INSERT, UPDATE, or DELETE statement.

-- Calculate department-wise average salary using a CTE
WITH avg_salary_cte AS (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
)
SELECT e.name, e.salary, a.avg_salary
FROM employees e
JOIN avg_salary_cte a ON e.department = a.department;


8. Data Transformation and Cleaning

CASE Statements

The CASE statement allows you to perform conditional logic within SQL queries.

-- Categorize employees based on salary
SELECT name,
CASE
WHEN salary < 50000 THEN 'Low'
WHEN salary BETWEEN 50000 AND 100000 THEN 'Medium'
ELSE 'High'
END AS salary_category
FROM employees;


String Functions

SQL offers several functions to manipulate strings:

-- Concatenate first and last names
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM employees;

-- Trim extra spaces from a string
SELECT TRIM(name) FROM employees;


Date and Time Functions

SQL allows you to work with date and time values:

-- Calculate tenure in days
SELECT name, DATEDIFF(CURDATE(), hire_date) AS days_tenure
FROM employees;


9. Database Management

Indexing

Indexes improve query performance by allowing faster retrieval of rows.

-- Create an index on the department column for faster lookups
CREATE INDEX idx_department ON employees(department);


Views

A view is a virtual table based on the result of a query. It simplifies complex queries by allowing you to reuse the logic.

-- Create a view for high-salary employees
CREATE VIEW high_salary_employees AS
SELECT name, salary
FROM employees
WHERE salary > 100000;

-- Query the view
SELECT * FROM high_salary_employees;


Transactions

A transaction ensures that a series of SQL operations are completed successfully. If any part fails, the entire transaction can be rolled back to maintain data integrity.

-- -- Transaction example
START TRANSACTION;
UPDATE employees SET salary = salary + 5000 WHERE department = 'HR';
DELETE FROM employees WHERE id = 10;
COMMIT; -- Commit the transaction if all


Best SQL Interview Resources
๐Ÿ‘10โค4
Here are some tricky๐Ÿงฉ SQL interview questions!

1. Find the second-highest salary in a table without using LIMIT or TOP.

2. Write a SQL query to find all employees who earn more than their managers.

3. Find the duplicate rows in a table without using GROUP BY.

4. Write a SQL query to find the top 10% of earners in a table.

5. Find the cumulative sum of a column in a table.

6. Write a SQL query to find all employees who have never taken a leave.

7. Find the difference between the current row and the next row in a table.

8. Write a SQL query to find all departments with more than one employee.

9. Find the maximum value of a column for each group without using GROUP BY.

10. Write a SQL query to find all employees who have taken more than 3 leaves in a month.

These questions are designed to test your SQL skills, including your ability to write efficient queries, think creatively, and solve complex problems.

Here are the answers to these questions:

1. SELECT MAX(salary) FROM table WHERE salary NOT IN (SELECT MAX(salary) FROM table)

2. SELECT e1.* FROM employees e1 JOIN employees e2 ON e1.manager_id = (link unavailable) WHERE e1.salary > e2.salary

3. SELECT * FROM table WHERE rowid IN (SELECT rowid FROM table GROUP BY column HAVING COUNT(*) > 1)

4. SELECT * FROM table WHERE salary > (SELECT PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY salary) FROM table)

5. SELECT column, SUM(column) OVER (ORDER BY rowid) FROM table

6. SELECT * FROM employees WHERE id NOT IN (SELECT employee_id FROM leaves)

7. SELECT *, column - LEAD(column) OVER (ORDER BY rowid) FROM table

8. SELECT department FROM employees GROUP BY department HAVING COUNT(*) > 1

9. SELECT MAX(column) FROM table WHERE column NOT IN (SELECT MAX(column) FROM table GROUP BY group_column)

Here you can find essential SQL Interview Resources๐Ÿ‘‡
https://t.iss.one/mysqldata

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

Hope it helps :)
๐Ÿ‘8โค3
You will be 20๐ฑ better at SQL

If you cover these topics in sequence:


๐—ฆ๐—ค๐—Ÿ ๐—•๐—ฎ๐˜€๐—ถ๐—ฐ

1. SELECT and WHERE Clauses | Filtering and retrieving data efficiently
2. GROUP BY and HAVING | Aggregating data with conditional logic
3. JOINs (INNER, LEFT, RIGHT, FULL) | Combining data from multiple tables
4. DISTINCT and LIMIT | Handling duplicates and limiting results

๐—ฆ๐—ค๐—Ÿ ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐—บ๐—ฒ๐—ฑ๐—ถ๐—ฎ๐˜๐—ฒ

1. Subqueries | Using queries inside queries for complex filtering
2. Window Functions (ROW_NUMBER, RANK, DENSE_RANK) | Analyzing data over partitions
3. CASE Statements | Conditional logic within your queries
4. Common Table Expressions (CTEs) | Simplifying complex queries for readability

๐—ฆ๐—ค๐—Ÿ ๐—”๐—ฑ๐˜ƒ๐—ฎ๐—ป๐—ฐ๐—ฒ
1. Recursive CTEs | Solving hierarchical and iterative problems
2. Pivot and Unpivot | Reshaping your data for better insights
3. Temporary Tables | Storing intermediate results for complex operations
4. Optimizing SQL Queries | Improving performance with indexing and query plans

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

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

Hope it helps :)
โค3๐Ÿ‘3
Learn SQL: Step-by-step Guide for Beginners!

๐Ÿ“„ 1. Start with the Basics โ€“ SQL Commands

SQL is divided into various command categories, each with a unique purpose:
- DML (Data Manipulation Language) โ€“ Commands like INSERT, UPDATE, and DELETE let you manage data within tables.
- DDL (Data Definition Language) โ€“ Commands like CREATE, DROP, and ALTER define the structure of your tables and databases.
- DQL (Data Query Language) โ€“ SELECT statements allow you to query and retrieve data from tables.
- DCL (Data Control Language) โ€“ GRANT and REVOKE control access to your database, essential for security.
- TCL (Transaction Control Language) โ€“ Use COMMIT, ROLLBACK, and SAVEPOINT to manage transactions effectively.

๐Ÿ” 2. Essential Operators

Understanding operators is key for crafting complex queries:
- Logical Operators โ€“ Use AND, OR, and NOT to create conditional statements.
- Comparison Operators โ€“ =, >, <, etc., help you filter results based on specific criteria.

๐Ÿ“… 3. Functions for Every Need

SQL offers various functions to manipulate and analyze data:
- Numeric Functions โ€“ Perform calculations and work with numbers.
- String Functions โ€“ Manage text data, perfect for working with names or descriptions.
- Datetime Functions โ€“ Handle date and time data, crucial for timelines and scheduling.
- NULL Functions โ€“ Deal with missing or undefined values in your data.

๐Ÿ“‚ 4. Data Types

Knowing data types (e.g., Numeric, String, Datetime, Boolean, JSON) is essential for defining your tables accurately. Choose the right data type to optimize storage and performance.

๐Ÿ”„ 5. Joins and Filtering

One of the most powerful aspects of SQL is combining data from multiple tables:
- JOIN Types โ€“ INNER JOIN, LEFT JOIN, RIGHT JOIN, and more allow you to bring related data together based on common keys.
- Filtering โ€“ Use WHERE, GROUP BY, HAVING, and ORDER BY clauses to refine your queries and get specific insights.

๐Ÿ’ผ 6. Working with Transactions

For applications where data integrity is key, learning transaction control (COMMIT, ROLLBACK) ensures consistency, especially in multi-step operations.

๐Ÿ“Œ Save this guide and keep it handy for your SQL learning journey! The more you practice, the more powerful your queries will become.

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

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

Hope it helps :)
๐Ÿ‘5
4 popular SQL interview questions:

๐Ÿ”ปWhat is a primary key?
โ€” A primary key is a field in a table that uniquely identifies each row or record in that table.

๐Ÿ”ปWhat is a foreign key?
โ€” A foreign key is a field in one table that refers to the primary key in another table, creating a relationship between the tables.

๐Ÿ”ปWhat are joins? Explain different types of joins.
โ€” A join is an SQL operation used to combine records from two or more tables. Common types of joins include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.

๐Ÿ”ปWhat is normalization?
โ€” Normalization is the process of organizing data to minimize redundancy and improve data integrity by dividing a database into multiple related tables.

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

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

Hope it helps :)
๐Ÿ‘5
14 Days Roadmap to learn SQL

๐——๐—ฎ๐˜† ๐Ÿญ: ๐—œ๐—ป๐˜๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป ๐˜๐—ผ ๐——๐—ฎ๐˜๐—ฎ๐—ฏ๐—ฎ๐˜€๐—ฒ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ฆ๐—ค๐—Ÿ
Topics to Cover:
- What is SQL?
- Different types of databases (Relational vs. Non-Relational)
- SQL vs. NoSQL
- Overview of SQL syntax
Practice:
- Install a SQL database (e.g., MySQL, PostgreSQL, SQLite)
- Explore an online SQL editor like SQLFiddle or DB Fiddle

๐——๐—ฎ๐˜† ๐Ÿฎ: ๐—•๐—ฎ๐˜€๐—ถ๐—ฐ ๐—ฆ๐—ค๐—Ÿ ๐—ค๐˜‚๐—ฒ๐—ฟ๐—ถ๐—ฒ๐˜€
Topics to Cover:
- SELECT statement
- Filtering with WHERE clause
- DISTINCT keyword
Practice:
- Write simple SELECT queries to retrieve data from single table
- Filter records using WHERE clauses

๐——๐—ฎ๐˜† ๐Ÿฏ: ๐—ฆ๐—ผ๐—ฟ๐˜๐—ถ๐—ป๐—ด ๐—ฎ๐—ป๐—ฑ ๐—™๐—ถ๐—น๐˜๐—ฒ๐—ฟ๐—ถ๐—ป๐—ด
Topics to Cover:
- ORDER BY clause
- Using LIMIT/OFFSET for pagination
- Comparison and logical operators
Practice:
- Sort data with ORDER BY
- Apply filtering with multiple conditions use AND/OR

๐——๐—ฎ๐˜† ๐Ÿฐ: ๐—ฆ๐—ค๐—Ÿ ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—”๐—ด๐—ด๐—ฟ๐—ฒ๐—ด๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐˜€
Topics to Cover:
- Aggregate functions (COUNT, SUM, AVG, MIN, MAX)
- GROUP BY and HAVING clauses
Practice:
- Perform aggregation on dataset
- Group data and filter groups using HAVING

๐——๐—ฎ๐˜† ๐Ÿฑ: ๐—ช๐—ผ๐—ฟ๐—ธ๐—ถ๐—ป๐—ด ๐˜„๐—ถ๐˜๐—ต ๐— ๐˜‚๐—น๐˜๐—ถ๐—ฝ๐—น๐—ฒ ๐—ง๐—ฎ๐—ฏ๐—น๐—ฒ๐˜€ - ๐—๐—ผ๐—ถ๐—ป๐˜€
Topics to Cover:
- Introduction to Joins (INNER, LEFT, RIGHT, FULL)
- CROSS JOIN and self-joins
Practice:
- Write queries using different types of JOINs to combine data from multiple table

๐——๐—ฎ๐˜† ๐Ÿฒ: ๐—ฆ๐˜‚๐—ฏ๐—พ๐˜‚๐—ฒ๐—ฟ๐—ถ๐—ฒ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ก๐—ฒ๐˜€๐˜๐—ฒ๐—ฑ ๐—ค๐˜‚๐—ฒ๐—ฟ๐—ถ๐—ฒ๐˜€
Topics to Cover:
- Subqueries in SELECT, WHERE, and FROM clauses
- Correlated subqueries
Practice:
- Write subqueries to filter, aggregate, an select data

๐——๐—ฎ๐˜† ๐Ÿณ: ๐——๐—ฎ๐˜๐—ฎ ๐— ๐—ผ๐—ฑ๐—ฒ๐—น๐—น๐—ถ๐—ป๐—ด ๐—ฎ๐—ป๐—ฑ ๐——๐—ฎ๐˜๐—ฎ๐—ฏ๐—ฎ๐˜€๐—ฒ ๐——๐—ฒ๐˜€๐—ถ๐—ด๐—ป
Topics to Cover:
- Understanding ERD (Entity Relationship Diagram)
- Normalization (1NF, 2NF, 3NF)
- Primary and Foreign Key
Practice:
- Design a simple database schema and implement it in your database

๐——๐—ฎ๐˜† ๐Ÿด: ๐— ๐—ผ๐—ฑ๐—ถ๐—ณ๐˜†๐—ถ๐—ป๐—ด ๐——๐—ฎ๐˜๐—ฎ - ๐—œ๐—ก๐—ฆ๐—˜๐—ฅ๐—ง, ๐—จ๐—ฃ๐——๐—”๐—ง๐—˜, ๐——๐—˜๐—Ÿ๐—˜๐—ง๐—˜
Topics to Cover:
- INSERT INTO statement
- UPDATE and DELETE statement
- Transactions and rollback
Practice:
- Insert, update, and delete records in a table
- Practice transactions with COMMIT and ROLLBACK

๐——๐—ฎ๐˜† ๐Ÿต: ๐—”๐—ฑ๐˜ƒ๐—ฎ๐—ป๐—ฐ๐—ฒ๐—ฑ ๐—ฆ๐—ค๐—Ÿ ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€
Topics to Cover:
- String functions (CONCAT, SUBSTR, etc.)
- Date functions (NOW, DATEADD, DATEDIFF)
- CASE statement
Practice:
- Use string and date function in queries
- Write conditional logic using CASE

๐——๐—ฎ๐˜† ๐Ÿญ๐Ÿฌ: ๐—ฉ๐—ถ๐—ฒ๐˜„๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—œ๐—ป๐—ฑ๐—ฒ๐˜…๐—ฒ๐˜€
Topics to Cover:
- Creating and using Views
- Indexes: What they are and how they work
- Pros and cons of using indexes
Practice:
- Create and query views
- Explore how indexes affect query performance

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

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

Hope it helps :)
๐Ÿ‘11โค1
Think you've mastered SQL just because you can use CTEs, views, or SQL commands?

Think again.

To be a true SQL MASTER, you need to: 

๐Ÿ”ฅ OPTIMIZE YOUR QUERIES for maximum speed and performance. 
๐Ÿ”ฅ Decode EXECUTION PLANS to fine-tune every detail. 
๐Ÿ”ฅ Know when to use INDEXES and avoid slow TABLE SCANS. 
๐Ÿ”ฅ Write queries that handle MASSIVE DATASETS without breaking a sweat. 
๐Ÿ”ฅ Continuously enhance your DATABASE DESIGN for improved performance.

SQL MASTERY isnโ€™t about knowing the basics ,itโ€™s about making your queries work SMARTER, FASTER, and at SCALE.

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

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

Hope it helps :)
๐Ÿ‘2