SQL Interview Questions N Answers-Easy
SQL Interview Questions N Answers-Easy
LEVEL - EASY
Q1: What is order of execution in sql?
FROM > WHERE > GROUP BY > HAVING > SELECT > ORDER BY > LIMIT
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
Q2: Find monthly sales and sort it by desc order
INPUT OUTPUT
Solution
MySql:
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
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
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;