Database Management System (DBMS) / SQL(STRUCTURED QUERY LANGUAGE)

Data Read Language/Data Query Language (DRL/DQL)

DQL or DRL is a subset of SQL used to read or retrieve data from a database.

It allows users to perform queries on one or more tables.


🧠 Key Command: SELECT

Used to fetch data from a table

It’s the only command in DQL


πŸ“„ Basic Syntax

CREATE TABLE students (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    age INT NOT NULL,
    grade VARCHAR(2)
);

INSERT INTO students (name, age, grade) VALUES
('Anya', 17, 'A'),
('Raj', 19, 'B'),
('Sara', 18, 'A'),
('Ravi', 20, 'C'),
('Tina', 16, 'B');

πŸ“Œ Examples

  • Fetch all data from a table:

SELECT * FROM students;
  • Fetch specific columns:

SELECT name, grade FROM students;
  • Fetch rows with a condition:

SELECT name FROM students WHERE grade = 'A';

βš™οΈ Additional Features with SELECT

  • ORDER BY – Sort results

SELECT * FROM students ORDER BY name ASC;
  • DISTINCT – Remove duplicate values

SELECT DISTINCT grade FROM students;
  • GROUP BY – Group rows with same values

SELECT grade, COUNT(*) FROM students GROUP BY grade;
  • HAVING – Condition after grouping

SELECT grade, COUNT(*) FROM students GROUP BY grade HAVING COUNT(*) > 1;

βœ… Summary

Command

Purpose

πŸ” SELECT

Fetches data from one or more tables

DQL is read-only β€” it does not change the data, just retrieves it.