0% found this document useful (0 votes)
2 views2 pages

SQL Interview Questions

The document provides a series of SQL interview questions and answers, covering fundamental concepts such as SQL definition, differences between DELETE, TRUNCATE, and DROP, and the use of WHERE and HAVING clauses. It includes example queries for selecting data, counting records, and identifying duplicates, as well as explanations of primary and foreign keys, and join types. Overall, it serves as a concise guide for preparing for SQL-related interviews.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

SQL Interview Questions

The document provides a series of SQL interview questions and answers, covering fundamental concepts such as SQL definition, differences between DELETE, TRUNCATE, and DROP, and the use of WHERE and HAVING clauses. It includes example queries for selecting data, counting records, and identifying duplicates, as well as explanations of primary and foreign keys, and join types. Overall, it serves as a concise guide for preparing for SQL-related interviews.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL Interview Questions & Answers

Q: What is SQL?
A: SQL (Structured Query Language) is used to store, manage, and retrieve data from relational
databases.

Q: What is the difference between DELETE, TRUNCATE, and DROP?


A: DELETE → removes specific rows from a table.
TRUNCATE → removes all rows from a table (faster).
DROP → deletes the entire table structure.

Q: What is the difference between WHERE and HAVING?


A: WHERE → filters rows before grouping.
HAVING → filters rows after grouping (used with GROUP BY).

Q: Write a query to select all columns from a table named Employees.


A: SELECT * FROM Employees;

Q: Write a query to find all employees in the HR department.


A: SELECT * FROM Employees WHERE Department = 'HR';

Q: How do you sort records in SQL?


A: By using ORDER BY.
Example:
SELECT * FROM Employees ORDER BY Salary DESC;

Q: What is a Primary Key?


A: A column (or set of columns) that uniquely identifies each row in a table.

Q: What is a Foreign Key?


A: A column that links one table to another, maintaining relationships between data.

Q: Write a query to count the number of employees.


A: SELECT COUNT(*) FROM Employees;

Q: Write a query to find the highest salary from the Employees table.
A: SELECT MAX(Salary) FROM Employees;

Q: How do you find duplicate records in a table?


A: SELECT Name, COUNT(*) FROM Employees GROUP BY Name HAVING COUNT(*) > 1;

Q: What is the difference between INNER JOIN and LEFT JOIN?


A: INNER JOIN → returns only matching rows from both tables.
LEFT JOIN → returns all rows from the left table, even if there’s no match in the right table.

You might also like