Chapter.01. Writting Basic Select Statement

download Chapter.01. Writting Basic Select Statement

of 5

Transcript of Chapter.01. Writting Basic Select Statement

  • 8/10/2019 Chapter.01. Writting Basic Select Statement

    1/5

    Chapter 1 : writting Basic select statement:--------------------------------------------username : scottpassword : tiger

    part I : how to wirte select statement---------------------------------------syntax......select select_listfrom table_name ;

    1.1 ) selecting certain columns-------------------------------select empno , ename , sal , deptnofrom emp ;

    1.2) selecting all columns--------------------------select *from emp ;

    1.3) to display tables in current user--------------------------------------

    select *from tab ;

    Desc emp

    1.4) writting expressions--------------------------select empno , ename, sal , sal + 100from emp

    select empno , ename, sal , sal + 100 * 5from emp

    select empno , ename, sal , (sal + 100) *5from emp ;

    select empno , ename, sal , sal / 100 * 5from emp ;

    1.5) using alias----------------

    select empno , ename, sal , (sal + 100)*5from emp ;

    select empno , ename, sal , (sal + 100)*5 as "New Salary"

    from emp ;

    select empno , ename, sal , (sal + 100)*5 as New_Salaryfrom emp ;

    select empno , ename, sal salary , (sal + 100)*5 as "New Salary"from emp ;

    1.6) concatenation operator:

  • 8/10/2019 Chapter.01. Writting Basic Select Statement

    2/5

    ----------------------------

    select empno , ename, job , ename || jobfrom emp ;

    select ' Employee No. ' || empno || ' his name is ' || ename ||' works as ' || jobfrom emp;

    1.7) supress duplication in rows---------------------------------

    select distinct jobfrom emp ;

    select distinct deptno , jobfrom emp ;

    ///////////////////////////////////////////////////////////////////////////////

    Part II) : Restricting Data :----------------------------Syntax:-------

    select select_listfrom table_namewhere condition

    Condition = column_name operator valuesal > 1000

    deptno = 10 ename = 'SCOTT'Examples--------2.1 ) using comparisone operators:----------------------------------select *

    from empwhere deptno = 30;

    select *from empwhere sal > 1500 ;

    select *from empwhere ename ='SCOTT' ;

    Operators : = > < >=

  • 8/10/2019 Chapter.01. Writting Basic Select Statement

    3/5

    where sal between 1000 and 3000 ;...................................................................................

    2.4) like operator------------------select *from empwhere ename like 'A%' ;

    select *from empwhere ename like '%R' ;

    select *from empwhere ename like '%L%' ;

    select *from empwhere ename like '%L%L%' ;

    select *from emp

    where ename like '_A%' ;

    select *from empwhere ename like '__A%' ;

    select *from empwhere ename like '%E_' ;

    2.5) null values:-----------------select *

    from empwhere comm is null

    select *from empwhere comm is not null

    2.6) more than one condition----------------------------and----select *from emp

    where deptno = 30 and sal > 1500 ;

    OR--select *from empwhere deptno = 30 or sal > 1500 ;

    Logic Tables------------

  • 8/10/2019 Chapter.01. Writting Basic Select Statement

    4/5

    OR true false nulltrue t t tfalse t f nnull t n n

    and true false null

    true t f nfalse f f fnull n f n

    NOT---select *from empwhere sal not between 1000 and 2000 ;

    select *from empwhere job not in ( 'ANALYST' , 'SALESMAN') ;

    select *from empwhere ename not like 'A%' ;

    /////////////////////////////////////////////////////////////////////////////////

    Part III : Sorting Data-----------------------Syntax :--------select select_listfrom table_nameorder by order_by_list ;

    Examples :

    ----------select * from emp order by sal ;select * from emp order by sal desc ;

    select empno , ename , deptno , sal from emp order by deptno , sal ;

    select empno , ename , deptno , salfrom emporder by deptno , sal desc ;

    select empno , ename , deptno , sal from emp order by 3 , 4 ;

    select empno , ename , sal salary from emp order by salary ;

    //////////////////////////////Chapter END//////////////////////////////////////

  • 8/10/2019 Chapter.01. Writting Basic Select Statement

    5/5