Q21. What is an INNER JOIN?
Answer:INNER JOIN
returns records that have matching values in both tables.
Example:
SELECT Employees.Name, Departments.DepartmentName
FROM Employees
INNER JOIN Departments ON Employees.DepartmentID = Departments.DepartmentID;
Q22. What is a LEFT JOIN?
Answer:LEFT JOIN
returns all records from the left table and matching records from the right table. Non-matching records from the right table are NULL.
Example:
SELECT Customers.Name, Orders.OrderDate
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;
Q23. What is a RIGHT JOIN?
Answer:RIGHT JOIN
returns all records from the right table and matching records from the left table.
Example:
SELECT Orders.OrderID, Customers.Name
FROM Orders
RIGHT JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
Q24. What is a FULL JOIN?
Answer:FULL JOIN
returns all records when there is a match in either left or right table.
Example:
SELECT A.Name, B.Department
FROM Employees A
FULL JOIN Departments B ON A.DepartmentID = B.DepartmentID;
Q25. What is a Self Join?
Answer:
A SELF JOIN
is a regular join, but the table joins with itself.
Example:
SELECT A.Name AS Employee1, B.Name AS Employee2
FROM Employees A, Employees B
WHERE A.ManagerID = B.EmployeeID;
Q26. What is a CROSS JOIN?
Answer:CROSS JOIN
returns the Cartesian product of the two tables.
Example: SELECT A.ProductName, B.CategoryName
FROM Products A
CROSS JOIN Categories B;
Q27. What is a Subquery?
Answer:
A Subquery is a query inside another query. It is used to return data that will be used in the main query.
Example: SELECT Name FROM Employees
WHERE DepartmentID = (SELECT DepartmentID FROM Departments WHERE DepartmentName = 'IT');
Q28. What is a View in SQL?
Answer:
A View is a virtual table based on the result of a SQL query. It does not store data permanently.
Example: CREATE VIEW IT_Employees AS
SELECT Name, Age FROM Employees WHERE Department = 'IT';
Q29. What is an Index in SQL?
Answer:
An Index improves the speed of data retrieval operations on a database table.
Example: CREATE INDEX idx_name ON Employees(Name);
Q30. What is the difference between WHERE and HAVING clauses?
Answer:
WHERE Clause | HAVING Clause |
---|---|
Used to filter rows before grouping | Used to filter groups after grouping |
Cannot use aggregate functions | Can use aggregate functions like COUNT(), SUM() |
Top 50 Intermediate SQL Interview Questions You Must Practice [With Examples]
Top 50 Advanced SQL Questions asked in Top Companies (with Answers + Examples)
2 thoughts on “Top 50 Basic Level SQL Interview Questions – Beginners Guide”