DBMS –25
(Database Management System )
Select
It is very important query command of SQL which
is used to retrieve the rows/tuples from one or more
tables. i.e. user can get back the data from database
using this command.
Many different clauses can be specified with it to get
data in different ways from database.
Syntax :
>Select [*/ columns/expression] from <Table name>
[where <condition> ]
[group by <col>[having<condition>]]
[order by <col> [ Asc / Desc ]] ;
<Table name > : Name of existing table to perform query.
[where <condition>] : To write condition for selecting
rows from table otherwise all records will be
retrieved.
[*/ columns/expression]: * is used to specify all columns.
Columns : column names to be retrieved from table.
Expression : expression to show result after calculation.
Eg. > Select * from first ; -It will show all columns.
>select rno, nm from first ; - show only given columns.
> Select tot * 100/500 from first ; - show result after
calculation on each value of tot in different rows of table.
> Select price * qty from inventory ; - show value of stock.
Examples with condition :
> Select bno, bname, author from book where price > 5000 ;
> Select tno, fare from train where sstn=‘pnp’ or estn=‘snp’ ;
> Select itnm, price * .50 from inventory
where price between 10000 and 20000 ;
> Select * from stud where dob < ’2005-01-01’ and city=‘SNP’ ;
> Select eid, ename, dept from emp
where dept in ( ‘Sales’, ‘Marketing’, ‘Account’ ) ;
> Select * from emp where ename like ‘_ _ _e_h’ ;
Home Work
Write and revise the topic
S.M. Hindu Sr. Sec. School ( Since 1914 )
Sonepat 131001 – (Hr.)
Ph. 0130-2222014, 2222608