SQL Practice
Table 1: Students
This table stores student information including name, gender, date of birth, and department
affiliation.
Column Name Data Type Description
StudentID INT (PK) Unique ID for each student
FirstName VARCHAR(50) Student's first name
LastName VARCHAR(50) Student's last name
Gender VARCHAR(10) 'Male', 'Female', or 'Other'
DateOfBirth DATE Date of birth
CourseID INT (FK) References
Courses(CourseID)
DepartmentID INT (FK) References
Departments(DepartmentID)
Table 2: Courses
This table stores information about academic courses including course title, duration, and
associated department.
Column Name Data Type Description
CourseID INT (PK) Unique ID for each course
CourseName VARCHAR(100) Title of the course
Credits INT Number of credit units
Instructor VARCHAR(100) Name of the course
instructor
DepartmentID INT (FK) References
Departments(DepartmentID)
Table 3: Departments
This table holds department-level details including department name and head of
department.
Column Name Data Type Description
DepartmentID INT (PK) Unique ID for each
department
DepartmentName VARCHAR(100) Name of the department
HeadOfDept VARCHAR(100) Name of the head of
department
SQL Query-Based Questions
Beginner Level (Basic SELECT, WHERE, ORDER BY)
• Write a SQL query to list the full names of all students who are female.
• Write a SQL query to find all students born after the year 2000.
• Write a SQL query to retrieve the names of all students ordered by LastName
alphabetically.
• Write a SQL query to find students from the 'Computer Science' department.
• Write a SQL query to select all columns from the Courses table.
• Write a SQL query to list all courses worth 3 credits.
• Write a SQL query to find all courses offered by the 'Science' department.
• Write a SQL query to retrieve all courses ordered by CourseName alphabetically.
• Write a SQL query to list all instructors who teach courses in the 'Mathematics'
department.
Intermediate Level (JOIN, GROUP BY, Aggregates)
• Write a SQL query to list students along with their department names using a JOIN.
• Write a SQL query to list all courses along with their department names using a JOIN.
• Write a SQL query to count the number of students in each department.
• Write a SQL query to find the average age of students in the 'Mechanical Engineering'
department.
• Write a SQL query to find departments with more than 10 students.
• Write a SQL query to find the youngest student in the 'Electrical Engineering'
department.
• Write a SQL query to count the number of courses in each department.
• Write a SQL query to find the average number of credits per department.
• Write a SQL query to list departments offering more than 5 courses.
• Write a SQL query to find the course with the highest number of credits in the
'Engineering' department.
Advanced Level (Subqueries, HAVING, CASE, Window Functions)
• Write a query to find departments that have no students assigned.
• Write a SQL query to return student names along with a label: 'Minor' if age < 18, else
'Adult'.
• Write a SQL query to return each course along with a label: 'Short' if Credits <= 2,
'Regular' otherwise.
• Write a SQL query to find students who belong to the department with the highest
number of students.
• Write a query to rank students by age within each department.
• Write a query to find the department where the head’s name starts and ends with the
same letter.
• Write a query to find departments that offer no courses.
• Write a SQL query to find courses offered by the department that offers the most
courses overall.