Retrieving record from a table


☞ Following are the topics to be covered :

1. Fetching specific record from a table.
2. Fetching all records with all the attributes.
3. Fetching all records with particular attributes.
4. Aliasing

Select Command

☞ It is used to fetch records/rows/tuples from a table.

☞ It is used to retrieve a subset of rows or columns from one or more tables present in a database.


Fetching specific record from a table

☞ To fetch the record from a table, we use the SELECT command.

☞ To fetch specific record, WHERE clause is used.

Syntax :

SELECT <column_1>, <column_2>, <column_3>, ..... <column_n>
FROM <table_name>
WHERE <condition>;

Example :

SELECT Rollno, name, fees
FROM Student
WHERE gender='M';

Fetching all records with all the attributes

☞ To fetch all records with all the fields from a table, we use the SELECT command.

☞ To select all the columns from a table, the asterisk (*) can be used.

Syntax :

SELECT * FROM <table_name>;

Example :

SELECT * FROM Student;

Fetching all records with particular fields

☞ To fetch all records with particular fields from a table, we use the SELECT command.

Syntax :

SELECT <column_1>, <column_2>, <column_3>, ..... <column_n>
FROM <table_name>;

Example :

SELECT Rollno, name, gender
FROM Student;

Aliasing

☞ It refers to giving a table, column, or expression a temporary or alternative name that can be used in SQL queries.

Syntax :

SELECT <column_1> AS <temporary_name>
FROM <table_name>;

Example :

SELECT Rollno, name AS Student_name
FROM Student;