DBMS – SQL Practice Queries

This section provides **hands-on SQL practice queries** for students to improve **query writing skills**, **logic**, and **exam performance**.

Assumed Table Structure

STUDENT
--------------------------------
RollNo (INT, PK)
Name (VARCHAR)
CourseID (INT)
Marks (INT)
City (VARCHAR)

COURSE
--------------------------------
CourseID (INT, PK)
CourseName (VARCHAR)
Duration (INT)

1. Basic SELECT Queries

  1. Display all records from STUDENT table.
  2. Display only Name and Marks of students.
  3. Display distinct CourseID from STUDENT table.
  4. Display students whose marks are greater than 60.

2. WHERE Clause & Operators

  1. Display students from city 'Delhi'.
  2. Display students whose marks are between 50 and 80.
  3. Display students enrolled in CourseID 101 or 102.
  4. Display students whose name starts with 'A'.

3. ORDER BY & LIMIT

  1. Display students in descending order of marks.
  2. Display top 5 students based on marks.
  3. Display students ordered by name alphabetically.

4. Aggregate Functions

  1. Count total number of students.
  2. Find maximum and minimum marks.
  3. Find average marks of students.
  4. Find total marks obtained by all students.

5. GROUP BY & HAVING

  1. Count number of students in each course.
  2. Display courses having more than 5 students.
  3. Find average marks per course.
  4. Display courses where average marks > 60.

6. SQL Joins

  1. Display student name with course name.
  2. Display all students even if course is not assigned.
  3. Display all courses even if no student is enrolled.

7. Sub Queries

  1. Display student with highest marks.
  2. Display students scoring above average marks.
  3. Display students enrolled in longest duration course.

8. UPDATE & DELETE Queries

  1. Update marks of a student with RollNo = 5.
  2. Increase marks by 5 for all students.
  3. Delete students whose marks are less than 30.

9. Exam-Level Practice

  1. Write SQL query to display second highest marks.
  2. Write SQL query to find duplicate records.
  3. Write SQL query to find students not enrolled in any course.
  4. Write SQL query using JOIN and GROUP BY.

Practice Task

✔ Practice writing each query manually ✔ Test queries in MySQL / PostgreSQL ✔ Modify queries with different conditions ✔ Prepare for viva & lab exams ✔ Try converting queries into MCQs