SQL Interview Questions N Answers-Easy
SQL Interview Questions N Answers-Easy
LEVEL - EASY
Rishabh Mishra
Q1: What is order of execution in sql?
FROM > WHERE > GROUP BY > HAVING > SELECT > ORDER BY > LIMIT
Rishabh Mishra
Q1: What is order of execution in sql?
FROM > WHERE > GROUP BY > HAVING > SELECT > ORDER BY > LIMIT
Example:
SELECT category, AVG(sales) AS avg_sales
FROM SalesData
category avg_sales
WHERE year > 2020
Electronics 121.9
GROUP BY category Home & Kitchen 91
HAVING COUNT(*) > 10 Books 88.2
ORDER BY avg_sales DESC
LIMIT 3
Rishabh Mishra
Q2: Find monthly sales and sort it by desc order
INPUT OUTPUT
Rishabh Mishra
Q2: Find monthly sales and sort it by desc order
Solution PostgreSQL:
Solution MySql:
Rishabh Mishra
Q3: Find the candidates best suited for an open Data Science job. Find candidates who are proficient
in Python, SQL, and Power BI.
Write a query to list the candidates who possess all of the required skills for the job. Sort the output
by candidate ID in ascending order.
INPUT OUTPUT
Rishabh Mishra
Q3: Find the candidates best suited for an open Data Science job. Find candidates who are proficient
in Python, SQL, and Power BI.
Write a query to list the candidates who possess all of the required skills for the job. Sort the output
by candidate ID in ascending order.
Query:
select candidate_id, count(skills) as skill_count
from Applications
where skills IN ('Python', 'SQL', 'Power BI')
group by candidate_id
having count(skills) = 3
order by candidate_id
Rishabh Mishra
1. If we divide 0 with a NULL, what will be the error/output
A) 0 B) NULL C) Division Error D) Query will not execute
2. If we divide a NULL with 1 (or any number), what will be the error/output
A) 0 B) NULL C) Division Error D) Query will not execute
NOTE: Perform any operation (sum, subtract, div, multiply) with NULL value, output will be NULL
Rishabh Mishra
6. WHERE FirstName LIKE 'A%’ . Which names does this query return? Select all that are applicable.
A) ARJUN B) TARA C) BHEEM D) ABHIMANYU
7. WHERE FirstName LIKE ’_R%’ . Which names does this query return? Select all that are applicable.
A) AR B) KRISHNA C) ARJUN D) ROHINI
8. WHERE FirstName LIKE ’%D%’ . Which names does this query return? Select all that are applicable.
A) NAKUL B) MADHAV C) SUNDAR D) MOON
9. WHERE FirstName LIKE ’M%N’ . Which names does this query return? Select all that are applicable.
A) MADHAV B) MADAN C) MOHAN D) NEON
10. WHERE FirstName LIKE ’M_ _ _%’ . Which names does this query return? Select all that are applicable.
A) MAN B) GOPAL C) MAANSI D) HARI
Rishabh Mishra
11. From the given WHERE clauses, which will return only rows that have a NULL in a column?
A) WHERE column_name <> NULL B) WHERE column_name IS NULL
C) WHERE column_name = NULL D) WHERE column_name NOT IN (*)
12. From the given WHERE clauses, which will return only rows that have a NOT NULL in a column?
A) WHERE column_name <> NULL B) WHERE column_name IS NULL
C) WHERE column_name = NULL D) WHERE column_name != NULL
13. Use of limit and offset in sql together in a sql query. Select all that are applicable.
A) SELECT * FROM artists LIMIT 5 OFFSET 2; B) SELECT * FROM artists 5, OFFSET 2;
C) SELECT * FROM artists LIMIT 5 , 2; D) SELECT * FROM artists 2, 5;
Rishabh Mishra
12. How to change a table name in SQL?
13. What is join in SQL? List its different types.
14. What is Normalization in SQL?
15. How to insert a date in SQL?
16. What are the TRUNCATE, DELETE and DROP statements?
17. What are the different types of SQL operators?
18. What are Aggregate and Scalar functions?
19. What does a window function do in SQL?
20. What are operators, share it’s types and examples
21. Difference between rank, dense_rank and row_number in sql
22. What are clustered and non-clustered index in SQL?
Rishabh Mishra
YouTube: https://www.youtube.com/@RishabhMishraOfficial
Instagram: https://www.instagram.com/rishabhnmishra/
LinkedIn: https://www.linkedin.com/in/rishabhnmishra/
By Rishabh Mishra
Rishabh Mishra