Monday, 29 May 2017

DBMS SELECT query ~ GNIITHELP

SELECT Query

Select query is used to retrieve data from a tables. It is the most used SQL query. We can retrieve complete tables, or partial by mentioning conditions using WHERE clause.

Syntax of SELECT Query

SELECT column-name1, column-name2, column-name3, column-nameN from table-name; 

Example for SELECT Query

Conside the following Student table,
S_idS_Nameageaddress
101Adam15Noida
102Alex18Delhi
103Abhi17Rohtak
104Ankit22Panipat
SELECT s_id, s_name, age from Student.
The above query will fetch information of s_id, s_name and age column from Student table
S_idS_Nameage
101Adam15
102Alex18
103Abhi17
104Ankit22

Example to Select all Records from Table

A special character asterisk * is used to address all the data(belonging to all columns) in a query. SELECT statement uses * character to retrieve all records from a table.
SELECT * from student; 
The above query will show all the records of Student table, that means it will show complete Student table as result.
S_idS_Nameageaddress
101Adam15Noida
102Alex18Delhi
103Abhi17Rohtak
104Ankit22Panipat

Example to Select particular Record based on Condition

SELECT * from Student WHERE s_name = 'Abhi';
103Abhi17Rohtak

Example to Perform Simple Calculations using Select Query

Conside the following Employee table.
eidNameagesalary
101Adam265000
102Ricky428000
103Abhi2210000
104Rohan355000
SELECT eid, name, salary+3000  from Employee;
The above command will display a new column in the result, showing 3000 added into existing salaries of the employees.
eidNamesalary+3000
101Adam8000
102Ricky11000
103Abhi13000
104Rohan8000

No comments:

Post a Comment