# 20 SQL Interview Questions – Intern Level Part 2 (Questions 6 through 10)
Table of Contents
6. How do you retrieve every column from a table named “employees”?
Use the SELECT statement with the wildcard * to fetch all columns:
SELECT *FROM employees;Here the asterisk acts as a wildcard, so the query returns every column for each row in the employees table.
7. Explain the WHERE clause in SQL
Definition
The WHERE clause filters query results using one or more conditions. It restricts the returned dataset to only the rows that satisfy the specified criteria.
Usage
Basic syntax:
SELECT column1, column2, ...FROM table_nameWHERE condition;
SELECT: specifies the columns to retrieve.FROM: identifies the table containing the data.WHERE: applies the filtering condition.
Example:
-- Fetch all employees in the IT departmentSELECT *FROM employeesWHERE department = 'IT';This query returns only the rows where the department column equals IT. The WHERE clause is essential for narrowing down results to the records that matter.
8. What is the purpose of the ORDER BY clause?
ORDER BY sorts query results based on the values of one or more columns, either ascending (ASC) or descending (DESC).
Usage
SELECT column1, column2, ...FROM table_nameORDER BY column1 [ASC|DESC], column2 [ASC|DESC], ...;
SELECT: identifies the columns to return.FROM: defines the source table.ORDER BY: lists the columns used for sorting.
Example:
-- Show all employees, sorted alphabetically by nameSELECT *FROM employeesORDER BY employee_name ASC;The result set is sorted by employee_name in ascending order (A–Z). Use ORDER BY when you need predictable, readable output.
9. Describe the GROUP BY clause and what it does
GROUP BY groups rows that share the same values in specified columns, which allows you to run aggregate functions such as SUM, AVG, COUNT, MAX, and MIN on each group.
Usage
SELECT column1, aggregate_function(column2), ...FROM table_nameGROUP BY column1, ...;
SELECT: chooses the columns and aggregates to return.FROM: names the table source.GROUP BY: lists the columns used for grouping.
Example:
-- Total number of products sold in each categorySELECT category, SUM(quantity_sold) AS total_soldFROM salesGROUP BY category;The query groups sales by category and calculates the total quantity sold for each category. GROUP BY helps you analyze distributions and summaries across segments of your data.
10. What is a JOIN in SQL and how does it work?
Definition
A JOIN combines data from two or more tables based on a related column. When your data is split across multiple tables, JOIN pulls matching rows together in a unified result set.
Syntax
SELECT column1, column2, ...FROM table1JOIN table2 ON join_condition;
SELECT: lists the columns to return from the join.FROM: specifies the primary table.JOIN: identifies the table to combine with the primary table.ON: defines the matching condition between the two tables.
Example:
-- Combine employee data with department namesSELECT employees.employee_id, employees.employee_name, departments.department_nameFROM employeesJOIN departments ON employees.department_id = departments.department_id;This query joins employees and departments using the shared department_id. The output includes employee details along with the name of their department.
Common JOIN types include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN, each suited to different data-combining scenarios.