SQL is a programming language specifically designed for managing, manipulating, and querying data stored in relational databases. In technical interviews, SQL questions assess a candidate’s understanding of database concepts, including data extraction, data manipulation, and database design. They often explore a candidate’s knowledge in creating complex queries, optimizing database performance, and understanding how to interact with data stored in a relational database.
Basic SQL Skills for Machine Learning
- 1.
What are the different types of JOIN operations in SQL?
Answer:INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN are different SQL join types, each with its distinct characteristics.
Join Types at a Glance
- INNER JOIN: Returns matching records from both tables.
- LEFT JOIN: Retrieves all records from the left table and matching ones from the right.
- RIGHT JOIN: Gets all records from the right table and matching ones from the left.
- FULL JOIN: Includes all records when there is a match in either of the tables.
Visual Representation

Code Example: SQL Joins
Here is the SQL code:
-- CREATE TABLES CREATE TABLE employees ( id INT PRIMARY KEY, name VARCHAR(100), department_id INT ); CREATE TABLE departments ( id INT PRIMARY KEY, name VARCHAR(100) ); -- INSERT SOME DATA INSERT INTO employees (id, name, department_id) VALUES (1, 'John', 1), (2, 'Alex', 2), (3, 'Lisa', 1), (4, 'Mia', 1); INSERT INTO departments (id, name) VALUES (1, 'HR'), (2, 'Finance'), (3, 'IT'); -- INNER JOIN SELECT employees.name, departments.name as department FROM employees INNER JOIN departments ON employees.department_id = departments.id; -- LEFT JOIN SELECT employees.name, departments.name as department FROM employees LEFT JOIN departments ON employees.department_id = departments.id; -- RIGHT JOIN SELECT employees.name, departments.name as department FROM employees RIGHT JOIN departments ON employees.department_id = departments.id; -- FULL JOIN SELECT employees.name, departments.name as department FROM employees FULL JOIN departments ON employees.department_id = departments.id; - 2.
Explain the difference between WHERE and HAVING clauses.
Answer: - 3.
How would you write a SQL query to select distinct values from a column?
Answer: - 4.
What does GROUP BY do in a SQL query?
Answer: - 5.
How can you aggregate data in SQL (e.g., COUNT, AVG, SUM, MAX, MIN)?
Answer: - 6.
Describe a subquery and its typical use case.
Answer: - 7.
Can you explain the use of indexes in databases and how they relate to Machine Learning?
Answer: - 8.
How would you optimize a SQL query that seems to be running slowly?
Answer:
Data Extraction and Transformation
- 9.
How do you handle missing values in a SQL dataset?
Answer: - 10.
Write a SQL query that joins two tables and retrieves only the rows with matching keys.
Answer: - 11.
How would you merge multiple result sets in SQL without duplicates?
Answer: - 12.
Create a SQL query to pivot a table transforming rows into columns.
Answer: - 13.
Explain the importance of data normalization in SQL and how it affects Machine Learning models.
Answer: - 14.
How can you extract time-based features from a SQL datetime field for use in a Machine Learning model?
Answer: - 15.
What are SQL Window Functions and how can they be used for Machine Learning feature engineering?
Answer: