What is the difference between UNION and UNION ALL in SQL?
UNION combines two result sets and removes duplicate rows, while UNION ALL combines them and keeps every row, which makes it faster.
Database 路 Intern to senior
SQL appears in backend, full stack and data interviews at every level. Freshers get joins, keys and the classic "second highest salary" query; mid-level candidates are asked about indexes and transactions; senior candidates are expected to read an execution plan and explain why a query is slow.
8 of 14 questions match
Clear filtersUNION combines two result sets and removes duplicate rows, while UNION ALL combines them and keeps every row, which makes it faster.
Use a subquery that takes the MAX salary below the overall MAX, or use DENSE_RANK() and pick rank 2, which also handles ties and generalises to the Nth highest.
Find duplicates with GROUP BY and HAVING COUNT(*) > 1, then delete them by numbering rows within each duplicate group with ROW_NUMBER() and removing every row after the first.
Normalization is organising tables to reduce redundancy and update anomalies: 1NF means atomic values, 2NF removes partial dependencies on part of a composite key, and 3NF removes dependencies between non-key columns.
ACID stands for Atomicity, Consistency, Isolation and Durability: a transaction either fully succeeds or fully fails, keeps the data valid, does not interfere with other transactions, and survives crashes once committed.
An index is a separate sorted data structure (usually a B-tree) that lets the database find rows without scanning the whole table, at the cost of extra storage and slower writes.
A clustered index defines the physical order in which the table's rows are stored, so there can be only one per table, while a non-clustered index is a separate structure that points back to the rows.
Choose SQL when your data is relational and you need transactions, joins and strong consistency; choose NoSQL when you need flexible schemas, very high write throughput or horizontal scaling for a specific access pattern.