SQL Interview Ques & ANS ๐ฅ๐
https://t.me/learndataanalysis/1156
https://t.me/learndataanalysis/1156
Here you can find the detailed answers for the above questions
๐๐
https://medium.com/@data_analyst/top-25-sql-questions-to-crack-your-next-data-analytics-interview-de6ab3634e1e
๐๐
https://medium.com/@data_analyst/top-25-sql-questions-to-crack-your-next-data-analytics-interview-de6ab3634e1e
๐4
Frequently asked SQL interview questions for Data Analyst/Data Engineer role-
1 - What is SQL and what are its main features?
2 - Order of writing SQL query?
3- Order of execution of SQL query?
4- What are some of the most common SQL commands?
5- Whatโs a primary key & foreign key?
6 - All types of joins and questions on their outputs?
7 - Explain all window functions and difference between them?
8 - What is stored procedure?
9 - Difference between stored procedure & Functions in SQL?
10 - What is trigger in SQL?
11 - Difference between where and having?
1 - What is SQL and what are its main features?
2 - Order of writing SQL query?
3- Order of execution of SQL query?
4- What are some of the most common SQL commands?
5- Whatโs a primary key & foreign key?
6 - All types of joins and questions on their outputs?
7 - Explain all window functions and difference between them?
8 - What is stored procedure?
9 - Difference between stored procedure & Functions in SQL?
10 - What is trigger in SQL?
11 - Difference between where and having?
๐11โค10
โCommon Mistakes In SQL JOINS
Interviewer can only trick you with two things in SQL JOIN questions!๐คท
Maximum people are making the most common mistake in SQL JOIN even after gaining few years of experience!
What makes SQL JOIN tricky?
1. Duplicate Values
2. NULL
Once you understand handling both, you can solve any of the toughest SQL JOIN questions in any interview.
Read more.....
Interviewer can only trick you with two things in SQL JOIN questions!๐คท
Maximum people are making the most common mistake in SQL JOIN even after gaining few years of experience!
What makes SQL JOIN tricky?
1. Duplicate Values
2. NULL
Once you understand handling both, you can solve any of the toughest SQL JOIN questions in any interview.
Read more.....
๐12๐2โค1๐1
Here are some essential SQL tips for beginners ๐๐
โ Primary Key = Unique Key + Not Null constraint
โ To perform case insensitive search use UPPER() function ex. UPPER(customer_name) LIKE โA%Aโ
โ LIKE operator is for string data type
โ COUNT(*), COUNT(1), COUNT(0) all are same
โ All aggregate functions ignore the NULL values
โ Aggregate functions MIN, MAX, SUM, AVG, COUNT are for int data type whereas STRING_AGG is for string data type
โ For row level filtration use WHERE and aggregate level filtration use HAVING
โ UNION ALL will include duplicates where as UNION excludes duplicates
โ If the results will not have any duplicates, use UNION ALL instead of UNION
โ We have to alias the subquery if we are using the columns in the outer select query
โ Subqueries can be used as output with NOT IN condition.
โ CTEs look better than subqueries. Performance wise both are same.
โ When joining two tables , if one table has only one value then we can use 1=1 as a condition to join the tables. This will be considered as CROSS JOIN.
โ Window functions work at ROW level.
โ The difference between RANK() and DENSE_RANK() is that RANK() skips the rank if the values are the same.
โ EXISTS works on true/false conditions. If the query returns at least one value, the condition is TRUE. All the records corresponding to the conditions are returned.
Like for more ๐๐
โ Primary Key = Unique Key + Not Null constraint
โ To perform case insensitive search use UPPER() function ex. UPPER(customer_name) LIKE โA%Aโ
โ LIKE operator is for string data type
โ COUNT(*), COUNT(1), COUNT(0) all are same
โ All aggregate functions ignore the NULL values
โ Aggregate functions MIN, MAX, SUM, AVG, COUNT are for int data type whereas STRING_AGG is for string data type
โ For row level filtration use WHERE and aggregate level filtration use HAVING
โ UNION ALL will include duplicates where as UNION excludes duplicates
โ If the results will not have any duplicates, use UNION ALL instead of UNION
โ We have to alias the subquery if we are using the columns in the outer select query
โ Subqueries can be used as output with NOT IN condition.
โ CTEs look better than subqueries. Performance wise both are same.
โ When joining two tables , if one table has only one value then we can use 1=1 as a condition to join the tables. This will be considered as CROSS JOIN.
โ Window functions work at ROW level.
โ The difference between RANK() and DENSE_RANK() is that RANK() skips the rank if the values are the same.
โ EXISTS works on true/false conditions. If the query returns at least one value, the condition is TRUE. All the records corresponding to the conditions are returned.
Like for more ๐๐
๐28โค11
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://t.me/mysqldata
Like this post if you need more ๐โค๏ธ
Hope it helps :)
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://t.me/mysqldata
Like this post if you need more ๐โค๏ธ
Hope it helps :)
๐15โค6
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.
Here you can find essential SQL Interview Resources๐
https://t.me/mysqldata
Like this post if you need more ๐โค๏ธ
Hope it helps :)
๐ 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.
Here you can find essential SQL Interview Resources๐
https://t.me/mysqldata
Like this post if you need more ๐โค๏ธ
Hope it helps :)
โค7๐7
Complete Roadmap to learn SQL in 2024 ๐๐
1. Basic Concepts
- Understand databases and SQL.
- Learn data types (INT, VARCHAR, DATE, etc.).
2. Basic Queries
- SELECT: Retrieve data.
- WHERE: Filter results.
- ORDER BY: Sort results.
- LIMIT: Restrict results.
3. Aggregate Functions
- COUNT, SUM, AVG, MAX, MIN.
- Use GROUP BY to group results.
4. Joins
- INNER JOIN: Combine rows from two tables based on a condition.
- LEFT JOIN: Include all rows from the left table.
- RIGHT JOIN: Include all rows from the right table.
- FULL OUTER JOIN: Include all rows from both tables.
5. Subqueries
- Use nested queries for complex data retrieval.
6. Data Manipulation
- INSERT: Add new records.
- UPDATE: Modify existing records.
- DELETE: Remove records.
7. Schema Management
- CREATE TABLE: Define new tables.
- ALTER TABLE: Modify existing tables.
- DROP TABLE: Remove tables.
8. Indexes
- Understand how to create and use indexes to optimize queries.
9. Views
- Create and manage views for simplified data access.
10. Transactions
- Learn about COMMIT and ROLLBACK for data integrity.
11. Advanced Topics
- Stored Procedures: Automate complex tasks.
- Triggers: Execute actions automatically based on events.
- Normalization: Understand database design principles.
12. Practice
- Use platforms like LeetCode, HackerRank, or learnsql for hands-on practice.
Here are some free resources to learn & practice SQL ๐๐
Udacity free course- https://imp.i115008.net/AoAg7K
SQL For Data Analysis: https://t.me/sqlanalyst
For Practice- https://stratascratch.com/?via=free
SQL Learning Series: https://t.me/sqlspecialist/567
Top 10 SQL Projects with Datasets: https://t.me/DataPortfolio/16
Join for more free resources: https://t.me/free4unow_backup
ENJOY LEARNING ๐๐
1. Basic Concepts
- Understand databases and SQL.
- Learn data types (INT, VARCHAR, DATE, etc.).
2. Basic Queries
- SELECT: Retrieve data.
- WHERE: Filter results.
- ORDER BY: Sort results.
- LIMIT: Restrict results.
3. Aggregate Functions
- COUNT, SUM, AVG, MAX, MIN.
- Use GROUP BY to group results.
4. Joins
- INNER JOIN: Combine rows from two tables based on a condition.
- LEFT JOIN: Include all rows from the left table.
- RIGHT JOIN: Include all rows from the right table.
- FULL OUTER JOIN: Include all rows from both tables.
5. Subqueries
- Use nested queries for complex data retrieval.
6. Data Manipulation
- INSERT: Add new records.
- UPDATE: Modify existing records.
- DELETE: Remove records.
7. Schema Management
- CREATE TABLE: Define new tables.
- ALTER TABLE: Modify existing tables.
- DROP TABLE: Remove tables.
8. Indexes
- Understand how to create and use indexes to optimize queries.
9. Views
- Create and manage views for simplified data access.
10. Transactions
- Learn about COMMIT and ROLLBACK for data integrity.
11. Advanced Topics
- Stored Procedures: Automate complex tasks.
- Triggers: Execute actions automatically based on events.
- Normalization: Understand database design principles.
12. Practice
- Use platforms like LeetCode, HackerRank, or learnsql for hands-on practice.
Here are some free resources to learn & practice SQL ๐๐
Udacity free course- https://imp.i115008.net/AoAg7K
SQL For Data Analysis: https://t.me/sqlanalyst
For Practice- https://stratascratch.com/?via=free
SQL Learning Series: https://t.me/sqlspecialist/567
Top 10 SQL Projects with Datasets: https://t.me/DataPortfolio/16
Join for more free resources: https://t.me/free4unow_backup
ENJOY LEARNING ๐๐
๐22โค9
The Only SQL You Actually Need For Your First Job DataAnalytics
The Learning Trap:
* Complex subqueries
* Advanced CTEs
* Recursive queries
* 100+ tutorials watched
* 0 practical experience
Reality Check:
75% of daily SQL tasks:
* Basic SELECT, FROM, WHERE
* JOINs
* GROUP BY
* ORDER BY
* Simple aggregations
* ROW_NUMBER
Like for detailed explanation โค๏ธ
#sql
The Learning Trap:
* Complex subqueries
* Advanced CTEs
* Recursive queries
* 100+ tutorials watched
* 0 practical experience
Reality Check:
75% of daily SQL tasks:
* Basic SELECT, FROM, WHERE
* JOINs
* GROUP BY
* ORDER BY
* Simple aggregations
* ROW_NUMBER
Like for detailed explanation โค๏ธ
#sql
โค23๐10
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.me/mysqldata
Like this post if you need more ๐โค๏ธ
Hope it helps :)
#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.me/mysqldata
Like this post if you need more ๐โค๏ธ
Hope it helps :)
#sql
๐18โค7๐2
๐ง๐ต๐ฒ ๐ฏ๐ฒ๐๐ ๐ฆ๐ค๐ ๐น๐ฒ๐๐๐ผ๐ป ๐๐ผ๐โ๐น๐น ๐ฟ๐ฒ๐ฐ๐ฒ๐ถ๐๐ฒ ๐๐ผ๐ฑ๐ฎ๐:
Master the core SQL statementsโthey are the building blocks of every powerful query you'll write.
-> SELECT retrieves data efficiently and accurately. Remember, clarity starts with understanding the result set you need.
-> WHERE filters data to show only the insights that matter. Precision is key.
-> CREATE, INSERT, UPDATE, DELETE allow you to mold your database like an artistโdesign it, fill it, improve it, or even clean it up.
In a world where everyone wants to take, give knowledge back.
Become an alchemist of your life. Learn, share, and build solutions.
Always follow best practices in SQL to avoid mistakes like missing WHERE in an UPDATE or DELETE. These oversights can cause chaos!
Without WHERE, you risk updating or deleting entire datasets unintentionally. That's a costly mistake.
But with proper syntax and habits, your databases will be secure, efficient, and insightful.
SQL is not just a skillโit's a mindset of precision, logic, and innovation.
Here you can find essential SQL Interview Resources๐
https://t.me/mysqldata
Like this post if you need more ๐โค๏ธ
Hope it helps :)
#sql
Master the core SQL statementsโthey are the building blocks of every powerful query you'll write.
-> SELECT retrieves data efficiently and accurately. Remember, clarity starts with understanding the result set you need.
-> WHERE filters data to show only the insights that matter. Precision is key.
-> CREATE, INSERT, UPDATE, DELETE allow you to mold your database like an artistโdesign it, fill it, improve it, or even clean it up.
In a world where everyone wants to take, give knowledge back.
Become an alchemist of your life. Learn, share, and build solutions.
Always follow best practices in SQL to avoid mistakes like missing WHERE in an UPDATE or DELETE. These oversights can cause chaos!
Without WHERE, you risk updating or deleting entire datasets unintentionally. That's a costly mistake.
But with proper syntax and habits, your databases will be secure, efficient, and insightful.
SQL is not just a skillโit's a mindset of precision, logic, and innovation.
Here you can find essential SQL Interview Resources๐
https://t.me/mysqldata
Like this post if you need more ๐โค๏ธ
Hope it helps :)
#sql
๐10โค6๐4
This is how you can learn SQL for 2025:
1. Learn FROM
2. Learn SELECT
3. Learn WHERE
4. Learn LEFT JOIN
5. Learn with data NOT tutorials
Starting can be overwhelming. but with consistent efforts things will get easier.
....read more
1. Learn FROM
2. Learn SELECT
3. Learn WHERE
4. Learn LEFT JOIN
5. Learn with data NOT tutorials
Starting can be overwhelming. but with consistent efforts things will get easier.
....read more
โค14๐14
Let's learn SQL together
SQL stands for Structured Query Language
This is an analogy I use to help me understand SQL:
- Americans speak = English
- Indian speak = Hindi
- Data analysts speak = SQL
SQL is a query language data analysts use to:
- Manipulate
- Transform
- Extract
Should I start teaching each SQL concept from scratch?
#sql
SQL stands for Structured Query Language
This is an analogy I use to help me understand SQL:
- Americans speak = English
- Indian speak = Hindi
- Data analysts speak = SQL
SQL is a query language data analysts use to:
- Manipulate
- Transform
- Extract
Should I start teaching each SQL concept from scratch?
#sql
๐192โค42๐5๐ค3๐คฃ3
Thanks for the amazing response on last post. Let's start with the very basic topic.
What is SQL?
"Guys, ever wondered how data analysts 'talk' to databases? Itโs with SQL!
Think of SQL as the language of data. Just like English or Hindi helps us communicate, SQL lets us interact with databases.
Hereโs the cool part: SQL is super easy to learn! It helps us:
1๏ธโฃ Extract data
2๏ธโฃ Transform it
3๏ธโฃ Make sense of it
Stay tuned, because next, weโll dive into the first step to master SQL!
#SQL #DataAnalytics #LearnSQL
What is SQL?
"Guys, ever wondered how data analysts 'talk' to databases? Itโs with SQL!
Think of SQL as the language of data. Just like English or Hindi helps us communicate, SQL lets us interact with databases.
Hereโs the cool part: SQL is super easy to learn! It helps us:
1๏ธโฃ Extract data
2๏ธโฃ Transform it
3๏ธโฃ Make sense of it
Stay tuned, because next, weโll dive into the first step to master SQL!
#SQL #DataAnalytics #LearnSQL
๐43โค12๐2๐1
Now, letโs kickstart our SQL journey with the SELECT statement!
SELECT is like the spotlightโit helps you pick and display specific data from a table.
Hereโs a quick example:
SELECT name, age
FROM Students;
๐ฏ This fetches the name and age of all students from the Students table.
Now your turn: Imagine a table named Employees. What would you write to fetch employee names and their salaries? Drop your answers in comments!
Stay tuned for tomorrowโs post where weโll talk about filtering data with WHERE!
#SQL #LearnSQL #DataSkills
SELECT is like the spotlightโit helps you pick and display specific data from a table.
Hereโs a quick example:
SELECT name, age
FROM Students;
๐ฏ This fetches the name and age of all students from the Students table.
Now your turn: Imagine a table named Employees. What would you write to fetch employee names and their salaries? Drop your answers in comments!
Stay tuned for tomorrowโs post where weโll talk about filtering data with WHERE!
#SQL #LearnSQL #DataSkills
๐49โค16
Day 3: Filtering Data with WHERE
Guys, ready to take your SQL game up a notch?
Today, letโs talk about the WHERE clauseโitโs your tool to filter data like a pro!
Hereโs how it works:
SELECT name, age
FROM Students
WHERE age > 18;
๐ฏ This gives you the names and ages of students older than 18.
Mini Challenge:
If you have an Employees table, how would you find employees earning more than 50,000? Drop your query below!
Tomorrow, weโll learn how to sort data with ORDER BY. Donโt miss it!
#SQL #LearnSQL #DataAnalytics
Guys, ready to take your SQL game up a notch?
Today, letโs talk about the WHERE clauseโitโs your tool to filter data like a pro!
Hereโs how it works:
SELECT name, age
FROM Students
WHERE age > 18;
๐ฏ This gives you the names and ages of students older than 18.
Mini Challenge:
If you have an Employees table, how would you find employees earning more than 50,000? Drop your query below!
Tomorrow, weโll learn how to sort data with ORDER BY. Donโt miss it!
#SQL #LearnSQL #DataAnalytics
๐27โค14