×
>
<

DBMS

DBMS SQL DQL | CrackEase

SQL DQL Commands

DQL Commands

DQL (Data Query Language) is used to retrieve data from a database. The primary DQL statement is SELECT.

Using SELECT you can retrieve full tables, specific columns (projection), filtered rows (selection) and calculated values.

SELECT

Basic Syntax

  
SELECT column1, column2, ...
FROM table_name;
  

Select specific columns

  
SELECT stuid, sname, score
FROM student;
  

Select all columns

Use the * wildcard to select every column in the table.

  
SELECT * FROM student;
  
Filter rows with WHERE

Return only rows that satisfy a condition.

  
SELECT * 
FROM student
WHERE branch = 'computers';
  
Simple expressions and calculations

You can compute values in the SELECT list; these do not change stored data unless you run an UPDATE.

  
SELECT stuid, sname, score, score + 5 AS adjusted_score
FROM student
WHERE score > 80;
  
Useful extensions (examples)
  
-- Distinct values
SELECT DISTINCT branch FROM student;

-- Sorting results
SELECT sname, score FROM student ORDER BY score DESC;

-- Limit number of rows (syntax varies by RDBMS)
SELECT * FROM student LIMIT 10;        -- MySQL/Postgres/SQLite
SELECT TOP 10 * FROM student;          -- SQL Server
  
Footer Content | CrackEase