sql Interview coding/Query questions
Difference between WHERE and HAVING clause in sql
1- How to find duplicates in a table
2- How to delete duplicates from a table
3- Difference between union and union all
4- Difference between rank,row_number and dense_rank
5- Find records in a table which are not present in another table
6- Find the second highest salary employees in each department
7- Find employees with salary more than their manager’s salary
8- Difference between inner and left join
9- update a table and swap gender values.
Database design and optimization
- Normalization
- Explain the normalization process and why it’s important.
- Discuss different normal forms (1NF, 2NF, 3NF, BCNF).
- Indexing:
- What are indexes, and how do they improve query performance?
- Write a query to create an index on the
salary
column of theemployee
table.
CREATE INDEX idx_salary
ON employee(salary);
- Transactions and Concurrency:
- Explain ACID properties.
- Write a query to start a transaction, update a record, and then commit the transaction.sqlCopy
START TRANSACTION;
UPDATE employee
SET salary = salary * 1.1
WHERE department = 'Sales';
COMMIT;