Notes

`SELECT` Query in DBMS (MySQL) [ English ]

< Prev Next >

Introduction

In a Database Management System (DBMS), data stored in tables must often be retrieved for viewing, analysis, or processing. The SELECT statement is used to fetch data from one or more tables in a database.

The SELECT query is one of the most commonly used SQL commands because it allows users to view stored information without modifying the data.

Definition

The SELECT query is a Data Manipulation Language (DML) command used to retrieve data from a table in a database.

It allows users to display specific columns or all columns from one or more tables.

Syntax

SELECT column1, column2, column3
FROM table_name;

Where:

Selecting All Columns

To retrieve all columns from a table, the asterisk (*) symbol is used.

Syntax

SELECT * FROM table_name;

Example

Suppose there is a table named students.

id name age course
1 Rahul 20 BCA
2 Anita 21 BBA
3 Rohit 19 BCA

Retrieve all records:

SELECT * FROM students;

Output

id name age course
1 Rahul 20 BCA
2 Anita 21 BBA
3 Rohit 19 BCA

Selecting Specific Columns

You can retrieve only specific columns instead of the entire table.

Example

SELECT name, course
FROM students;

Output

name course
Rahul BCA
Anita BBA
Rohit BCA

Using DISTINCT

The DISTINCT keyword is used to remove duplicate values from the result.

Syntax

SELECT DISTINCT column_name
FROM table_name;

Example

SELECT DISTINCT course
FROM students;

Output

course
BCA
BBA

Key Points

Summary

The SELECT query is used to retrieve data from tables in a database. It allows users to view complete records or specific columns depending on their requirements. Because of its flexibility and importance in data retrieval, the SELECT statement is considered one of the core commands in SQL.

< Prev Next >