Tuesday 28 May 2013

Arithmetic Expressions in SELECT statement

You may need to modify the way in which data is displayed, perform calculations, etc.

   Operator       Description


     +                     Add
      -                   Subtract
      *                  Multiply
      /                   Divide

Using Arithmetic Operators 

If we need to show Annual salary of employes then;


Another example:


Selecting Specific Columns




In the above example we 've selected only 3 columns from the table.

Errors: 

If we want to select column that is not in that table then SQL returns an error. 
Example:







Basic Select Statement or Selecting ALL Columns

Syntax of SELECT Statement


SELECT *|{[DISTINCT] column|expression [alias],....}
FROM table;

> SELECT identifies what columns
> FROM identifies which table

Selecting All Columns

SELECT * 
FROM dept;

Result:




Unit 1 :- SELECT Staments (With Example)

A SELECT statement retrieves information from the database. Using a SELECT statement you can do the following things:

> Projection: You can choose as few or many columns of the table as you required. (Column filtration)
> Selection: You can use various criteria to restrict the rows that you see. (Row filtration)
> Joining: You can use the join capability in SQL to bring together data that is stored in different tables by creating a link between them.

In this section I am going to use two table (emp and dept) shown below.
Here are the topics that I'll cover in SELECT Statement Section.

1) Basic Select Statement or Selecting ALL Columns
2) Selecting Specific Columns
3) Use of Arithmetic Expressions in SELECT statement.
4) Operator Precedence in SELECT statement and using Parenthesis
5) Column Aliases in SELECT statement. (With Example)
6) Concatenation Operator in SELECT statement (With Example)
7) Literal Character String in SELECT statement (With Example)
8) DISTINCT - Eliminating Duplicate Rows (With Example)

In this Tutorial I've used TWO TABLES named: emp and dept.
Here are the Structure of Two Table:  ( CLICK on the image to see better)




Data in EMP and DEPT Table: ( CLICK on the image to see better)