• Home
  • Data Query Language(DQL) in sql

    Query:

    To retrieve the data from the table according to the user's instruction is called as query. The select statement can be used to retrieve information from a database. The select statement can be used for:

    • Projection: the projection capability of SQL helps us to chose the column in a table that you want your query should return.
    • Selection: the selection capability of SQL helps us to choose the rows in a table that you want your query should return.
    • Joining: the joining capability of SQL helps you to bring together data that is stored in different tables by creating a link between them.

    Example

    Select * from table;
    Where select identifies which columns
    From identifies which table
    Table specifies the table from which the data has to retrieve.

    Select * from dept;
    The above statement will retrieve all the records of dept table.

    Select dept-id, dept-name, manager-id
    From dept;
    The above statements will retrieve the dept-id, dept-name, manager-id column from dept table.


    Using arithmetic expression in select statement:

    Sometimes you may need to modify the way in which data is displayed or perform calculations. All these operations are possible using arithmetic expression. An arithmetic expression can contain column names, constant numeric values, and arithmetic operator. Some arithmetic operators are given below:

    Operator Description
    + add
    - subtract
    * multiplication
    / division


    Example:

    Select emp-name, emp-sal, emp-sal+3000
    From employee;
    The above example will show emp-name, emp-sal and their increased salary, which is Rs. 3000/- more from the actual salary.


    Uses of alias in select statement:

    Whenever oracle server returns the result of a query normally it uses the name of the selected column heading. This heading may not be descriptive hence it may be difficult to understand. You can change the column heading by using a column alias. By default, alias headings appear in uppercase. If the alias contains spaces or special characters(such as # or $), or is case sensitive, enclose the alias in double quotation marks( " " ).

    Example:

    Select emp-name AS EMP-NAME
    From employee;
    In the above example the query will return that the column heading emp-name as EMP-NAME.


    Concatenation operator:

    A concatenation operator :

    • • Concatenates columns or character strings to other columns.
    • • Is represented by two vertical bars.
    • • Creates a resultant column that is a character expression.
    For example:

    Select last_name || job_id AS "Emp"
    From employee ;
    In this example, last_name and job_id are concatenated, and they are given the alias Employee. It is pointed that the employee last name and job code are combined to make a single output column.


    Some operators

    Between....and....operator:

    If you want to display rows based on range of a value in that case the between....and...operator is used.

    Example;

    Select emp-name, emp-salary
    From employee
    Where emp-salary between 12000 and 25000;
    In the above example the query will return all the value of emp-name and emp-salary where emp-salary falls between 12000 and 25000.


    Note: the between....and....operator includes the lower limit as well as upper limit.

    In operator:

    The in operator can be used in a situation where you have to make a search based on a list of values.


    About the Author



    Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

    We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





     PreviousNext