SELECT COMMAND

 The DQL (Data Query Language) is a subset of SQL used to retrieve data from the database. In essence, DQL focuses on querying data stored in tables, and its most common command is SELECT.


1. DQL Commands

The primary command in DQL is:

  • SELECT: Used to retrieve data from one or more tables.

DQL allows you to:

  • Specify which columns or rows to retrieve.
  • Filter data using conditions.
  • Sort data.
  • Aggregate and group data.
  • Join data from multiple tables.

2. Syntax

Basic Syntax

sql

SELECT column1, column2, ... FROM table_name WHERE condition;
  • column1, column2: Columns to retrieve.
  • table_name: The table to query data from.
  • condition: Filter to retrieve specific rows.

3. Types of Queries

A. Retrieve All Columns

Retrieve all columns from a table:

sql

SELECT * FROM employees;

B. Retrieve Specific Columns

Retrieve only specific columns:

sql

SELECT emp_id, emp_name, salary FROM employees;

C. Apply Filtering with WHERE

Retrieve rows based on conditions:

sql

SELECT emp_id, emp_name, salary FROM employees WHERE department_id = 20;

Comments

Popular posts from this blog

dbms exercise 2

alter table

DDL create table