
5 Most Asked SQL Interview Questions
What is the difference between WHERE and HAVING in SQL? Answer: The main difference is WHERE filters rows before grouping, while HAVING filters groups after aggregation. WHERE Used with SELECT, UPDATE, DELETE Filters individual rows Cannot use aggregate functions like SUM() or COUNT() Example SELECT * FROM employees WHERE salary > 50000; HAVING Used with GROUP BY Filters grouped data Works with aggregate functions Example SELECT department, COUNT( ) FROM employees GROUP BY department HAVING COUNT( ) > 5; What is the difference between INNER JOIN and LEFT JOIN? Answer: INNER JOIN Returns only matching records from both tables. LEFT JOIN Returns all records from the left table and matching records from the right table. If no match is found, NULL values are returned. Example SELECT e.name, d.department_name FROM employees e INNER JOIN departments d ON e.department_id = d.id; What is a Primary Key in SQL? Answer: A Primary Key is a column (or group of columns) that uniquely identifies each
Continue reading on Dev.to Tutorial
Opens in a new tab


