SQL Programming Resources
75.6K subscribers
503 photos
13 files
440 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
The Secret to learn SQL:
It's not about knowing everything
It's about doing simple things well

What You ACTUALLY Need:

1. SELECT Mastery

* SELECT * LIMIT 10
(yes, for exploration only!)
* COUNT, SUM, AVG
(used every single day)
* Basic DATE functions
(life-saving for reports)
* CASE WHEN

2. JOIN Logic

* LEFT JOIN
(your best friend)
* INNER JOIN
(your second best friend)
* That's it.

3. WHERE Magic
* Basic conditions
* AND, OR operators
* IN, NOT IN
* NULL handling
* LIKE for text search

4. GROUP BY Essentials
* Basic grouping
* HAVING clause
* Multiple columns
* Simple aggregations

Most common tasks:
* Pull monthly sales
* Count unique customers
* Calculate basic metrics
* Filter date ranges
* Join 2-3 tables

Focus on:
* Clean code
* Clear comments
* Consistent formatting
* Proper indentation

Here you can find essential SQL Interview Resources👇
https://t.iss.one/mysqldata

Like this post if you need more 👍❤️

Hope it helps :)

#sql
👍112
📖 SQL Short Notes 📝 Beginner To Advance
👍11👏2
🖥 Joins In SQL All Types
👍82
The GROUP BY clause in SQL is used to arrange identical data into groups. This is particularly useful when combined with aggregate functions like COUNT(), SUM(), AVG(), MIN(), and MAX(). The GROUP BY clause groups rows that have the same values in specified columns into summary rows.

Basic Syntax

SELECT column1, aggregate_function(column2)
FROM table_name
WHERE condition
GROUP BY column1;


Example 1: Counting Rows

Suppose you have a table called employees with the following structure:

| id | department | salary |
|----|------------|--------|
| 1 | HR | 50000 |
| 2 | IT | 60000 |
| 3 | HR | 55000 |
| 4 | IT | 70000 |
| 5 | Sales | 65000 |

To find out how many employees are in each department, you can use:

SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department;


Result:

| department | employee_count |
|------------|----------------|
| HR | 2 |
| IT | 2 |
| Sales | 1 |

Example 2: Summing Salaries

To calculate the total salary paid to employees in each department, you can use:

SELECT department, SUM(salary) AS total_salary
FROM employees
GROUP BY department;


Result:

| department | total_salary |
|------------|--------------|
| HR | 105000 |
| IT | 130000 |
| Sales | 65000 |

Example 3: Average Salary

To find the average salary of employees in each department:

SELECT department, AVG(salary) AS average_salary
FROM employees
GROUP BY department;


Result:

| department | average_salary |
|------------|----------------|
| HR | 52500 |
| IT | 65000 |
| Sales | 65000 |

Example 4: Grouping by Multiple Columns

You can also group by multiple columns. For instance, if you had another column for job_title:

| id | department | job_title | salary |
|----|------------|-----------|--------|
| 1 | HR | Manager | 50000 |
| 2 | IT | Developer | 60000 |
| 3 | HR | Assistant | 55000 |
| 4 | IT | Manager | 70000 |
| 5 | Sales | Executive | 65000 |

To count employees by both department and job_title:

SELECT department, job_title, COUNT(*) AS employee_count
FROM employees
GROUP BY department, job_title;


Result:

| department | job_title | employee_count |
|------------|-----------|----------------|
| HR | Manager | 1 |
| HR | Assistant | 1 |
| IT | Developer | 1 |
| IT | Manager | 1 |
| Sales | Executive | 1 |

Important Notes

1. Aggregate Functions: Any column in the SELECT statement that is not an aggregate function must be included in the GROUP BY clause.

2. HAVING Clause: You can filter groups using the HAVING clause, which is similar to the WHERE clause but is used for aggregated data. For example:

   SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 1;


This would return only departments with more than one employee.

Conclusion

The GROUP BY clause is a powerful tool in SQL for summarizing data. It allows you to analyze and report on your datasets effectively by grouping similar data points and applying aggregate functions.
10👍8
Types Of Database YOU MUST KNOW

1. Relational Databases (e.g., MySQL, Oracle, SQL Server):
- Uses structured tables to store data.
- Offers data integrity and complex querying capabilities.
- Known for ACID compliance, ensuring reliable transactions.
- Includes features like foreign keys and security control, making them ideal for applications needing consistent data relationships.

2. Document Databases (e.g., CouchDB, MongoDB):
- Stores data as JSON documents, providing flexible schemas that can adapt to varying structures.
- Popular for semi-structured or unstructured data.
- Commonly used in content management and automated sharding for scalability.

3. In-Memory Databases (e.g., Apache Geode, Hazelcast):
- Focuses on real-time data processing with low-latency and high-speed transactions.
- Frequently used in scenarios like gaming applications and high-frequency trading where speed is critical.

4. Graph Databases (e.g., Neo4j, OrientDB):
- Best for handling complex relationships and networks, such as social networks or knowledge graphs.
- Features like pattern recognition and traversal make them suitable for analyzing connected data structures.

5. Time-Series Databases (e.g., Timescale, InfluxDB):
- Optimized for temporal data, IoT data, and fast retrieval.
- Ideal for applications requiring data compression and trend analysis over time, such as monitoring logs.

6. Spatial Databases (e.g., PostGIS, Oracle, Amazon Aurora):
- Specializes in geographic data and location-based queries.
- Commonly used for applications involving maps, GIS, and geospatial data analysis, including earth sciences.

Different types of databases are optimized for specific tasks. Relational databases excel in structured data management, while document, graph, in-memory, time-series, and spatial databases each have distinct strengths suited for modern data-driven applications.
12👍2
If you are interested to learn SQL for data analytics purpose and clear the interviews, just cover the following topics

1)Install MYSQL workbench
2) Select
3) From
4) where
5) group by
6) having
7) limit
8) Joins (Left, right , inner, self, cross)
9) Aggregate function ( Sum, Max, Min , Avg)
9) windows function ( row num, rank, dense rank, lead, lag, Sum () over)
10)Case
11) Like
12) Sub queries
13) CTE
14) Replace CTE with temp tables
15) Methods to optimize Sql queries
16) Solve problems and case studies at Ankit Bansal youtube channel

Trick: Just copy each term and paste on youtube and watch any 10 to 15 minute on each topic and practise it while learning , By doing this , you get the basics understanding

17) Now time to go on youtube and search data analysis end to end project using sql

18) Watch them and practise them end to end.

17) learn integration with power bi

In this way , you will not only memorize the concepts but also learn how to implement them in your current working and projects and will be able to defend it in your interviews as well.

Like for more

Here you can find essential SQL Interview Resources👇
https://t.iss.one/DataSimplifier

Hope it helps :)
👍96
This is very important guys 🚨

Guys as there are rumours around Telegram usage, to avoid any inconvenience, you can join the whatsapp channel here
👇👇
https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v

It took lot of efforts to build this community, please join fast so that we can continue our initiative to help you all 🚀
👍8🎉4
SQL best practices

Use EXISTS in place of IN wherever possible
Use table aliases with columns when you are joining multiple tables
Use GROUP BY instead of DISTINCT.
Add useful comments wherever you write complex logic and avoid too many comments.
Use joins instead of subqueries when possible for better performance.
Use WHERE instead of HAVING to define filters on non-aggregate fields
Avoid wildcards at beginning of predicates (something like '%abc' will cause full table scan to get the results)
Considering cardinality within GROUP BY can make it faster (try to consider unique column first in group by list)
Write SQL keywords in capital letters.
Never use select *, always mention list of columns in select clause.
Create CTEs instead of multiple sub queries , it will make your query easy to read.
Join tables using JOIN keywords instead of writing join condition in where clause for better readability.
Never use order by in sub queries , It will unnecessary increase runtime.
If you know there are no duplicates in 2 tables, use UNION ALL instead of UNION for better performance
Always start WHERE clause with 1 = 1.This has the advantage of easily commenting out conditions during debugging a query.
Taking care of NULL values before using equality or comparisons operators. Applying window functions. Filtering the query before joining and having clause.
Make sure the JOIN conditions among two table Join are either keys or Indexed attribute.

Here you can find essential SQL Interview Resources👇
https://t.iss.one/mysqldata

Like this post if you need more 👍❤️

Hope it helps :)
👍10👏1
SQL Joins: Unlock the Secrets Data Aficionado's

♐️ SQL joins are the secret ingredients that bring your data feast together, they are the backbone of relational database querying, allowing us to combine data from multiple tables.

➠ Let's explore the various types of joins and their applications:

1. INNER JOIN
- Returns only the matching rows from both tables
- Use case: Finding common data points, e.g., customers who have made purchases

2. LEFT JOIN
- Returns all rows from the left table and matching rows from the right table
- Use case: Retrieving all customers and their orders, including those who haven't made any purchases

3. RIGHT JOIN
- Returns all rows from the right table and matching rows from the left table
- Use case: Finding all orders and their corresponding customers, including orders without customer data

4. FULL OUTER JOIN
- Returns all rows from both tables, with NULL values where there's no match
- Use case: Comprehensive view of all data, identifying gaps in relationships

5. CROSS JOIN
- Returns the Cartesian product of both tables
- Use case: Generating all possible combinations, e.g., product variations

6. SELF JOIN
- Joins a table with itself
- Use case: Hierarchical data, finding relationships within the same table

🚀 Advanced Join Techniques

1. UNION and UNION ALL
- Combines result sets of multiple queries
- UNION removes duplicates, UNION ALL keeps them
- Use case: Merging data from similar structures

2. Joins with NULL Checks
- Useful for handling missing data or exclusions

💡 SQL Best Practices for Optimal Performance

1. Use Appropriate Indexes : Create indexes on join columns and frequently filtered fields.

2. Leverage Subqueries: Simplify complex queries and improve readability.

3. Utilize Common Table Expressions (CTEs): Enhance query structure and reusability.

4. Employ Window Functions: For advanced analytics without complex joins.

5. Optimize Query Plans: Analyze and tune execution plans for better performance.

6. Master Regular Expressions: For powerful pattern matching and data manipulation.
10👍9👏1
20 medium-level SQL interview questions:

1. Write a SQL query to find the second-highest salary.
2. How would you optimize a slow SQL query?
3. What is the difference between INNER JOIN and OUTER JOIN?
4. Write a SQL query to find the top 3 departments with the highest average salary.
5. How do you handle duplicate rows in a SQL query?
6. Write a SQL query to find the employees who have the same name and work in the same department.
7. What is the difference between UNION and UNION ALL?
8. Write a SQL query to find the departments with no employees.
9. How do you use indexing to improve SQL query performance?
10. Write a SQL query to find the employees who have worked for more than 5 years.
11. What is the difference between SUBQUERY and JOIN?
12. Write a SQL query to find the top 2 products with the highest sales.
13. How do you use stored procedures to improve SQL query performance?
14. Write a SQL query to find the customers who have placed an order but have not made a payment.
15. What is the difference between GROUP BY and HAVING?
16. Write a SQL query to find the employees who work in the same department as their manager.
17. How do you use window functions to solve complex queries?
18. Write a SQL query to find the top 3 products with the highest average price.
19. What is the difference between TRUNCATE and DELETE?
20. Write a SQL query to find the employees who have not taken any leave in the last 6 months.
👍171👏1