SELECT Query in DBMS

SELECT Query in DBMS

 

In this article we will learn about SELECT Query in DBMS.

  • A SELECT  query is used to retrieve data(records) from the table
  • We can retrieve complete table data, or specific records by specifying conditions using the WHERE clause.

Syntax 

SELECT column1, column2, ...
FROM table_name;
SELECT Query in DBMS

Displaying only specific columns using SELECT Query in DBMS

Consider a table student where you need to display a student name, ID, and score

SELECT stuid,sname,score 
from student;

O/P

  stuid snamescore
66Trishaank92
82Srinivas62
73Prashanth78
79Sanjay85
91Chandana90

 

Display all records present in the table using SELECT Query in DBMS

The ‘*’ operator is used to display  all the columns present in the table

SELECT * from student;
tuidsnamebranchdobscore
66Trishaankcomputers24-07-199892
82Srinivascomputers7-07-199662
73PrashanthPhysics17-08-199778
79SanjayMaths12-09-199785
91ChandanaBiology7-05-199790

All the columns in the table get displayed.

 

 Retrieve  records based on some specified condition

Only those records that satisfy the condition specified in the ‘where’ clause are displayed

Display records of those students from the computers department

SELECT * from
student
where branch='computers';

O/P

stuidsnamebranchdobscore
66Trishaankcomputers24-07-199892
82Srinivascomputers7-07-199662

 

Performing some calculations on the column using SELECT

  • We can use simple arithmetic operators upon column data while displaying records
  • But these changes are not affected in the actual database table they are just  used for display purpose

Increase score of students by 5 marks who are having a score greater than 80

SELECT stuid,sname,score,score+5 
from student
where score>80;

O/P

stuidsnamescorescore+5
66Trishaank9297
79Sanjay8590
91Chandana9095

5 marks will be added to all students who are having ‘score’ greater than 80 are displayed

Learn more about DBMS here on this page.

One comment on “SELECT Query in DBMS”