sql select statements

Using SQL Select Statements

How to use SQL select statements?

In this article we are going to learn how to use SQL select statements to retrieve data from tables or views. In database, data stored in tables format and if you want to check that data then you should know how to use Oracle SQL statements.

Click here to learn how to use Column Aliases in SQL statements

Important points for SQL select statements.

There are three ways to retrieve data from tables using SQL select statements.

1. SELECTION: If you retrieve data ROW wise from tables that is called SELECTION.

2. PROJECTION: If you retrieve data COLUMN wise from table that is called PROJECTION.

3. JOINS: If you select data from multiple tables with single query that method called joins.

How to write SQL statements?

  1. You can write it in any case, SQL statements are not case sensitive.
  2. You can write SQL statements in multiple lines.
  3. Do not abbreviated or split the keywords across the line.
  4. To better understanding of SQL queries, place Clauses in separate line.
  5. To execute any query on SQL prompt the semicolon is required, but if you are using SQL Developer tool then semicolon is optional.

Use below query to select all Columns from any tables. 

SQL> select * from ocp;

If you want to select all columns from any table so use * (asterisk) with select command as in above example, in above example: [select (command) * (asterisk) from (keyword) ocp (table name)].

How to select any specific columns form any tables?

For selecting any specific columns from any tables, just specify the name of column with the select command same as following examples, suppose i have a one table which is name is OCP and it’s have 8 columns like (ENAME, JOB, SALARY, DEPTNO, COMM, JDATE, EMPNO, MGR), So i just want to select three columns from this table, using below query.

SQL> select ename, job, salary from ocp;

How to use Arithmetic operators with select command?

Types of Arithmetic operators is:

  1. + (Add)
  2. – (Subtract)
  3. * (Multiply)
  4. / (Divide)

1. Using “+” (Add)

SQL> select ename, salary + 100 from ocp;

In above query, select two columns first ename, second salary, and using Add (+) operator with salary column, that means give 100 rupees incentive to each employees.

2. Using “*” (Multiply)

 SQL> select ename, salary * 12 from ocp;

In above example we are using “*” multiply operator which is calculate annual salary of each employees.

How to check current Date of Database server ?

 SQL> select sysdate from dual;

In above query, we are using sysdate this is predefined functionality of the Oracle Database which always showing system current Date, and dual also is predefined object which is we use for temporary calculations.

3. Using “-” (Subtract)

 SQL> select ename, sysdate - jdate from ocp;

In above query, we are using subtract operator which is used to calculate number of working days of each employees, from joining date to till date.

4. Using “/” Divide operator 

 SQL> select ename, (sysdate - jdate)/7 from ocp;

In above query, we are using subtract and divide operator together to calculating number of working weeks of each employees.

You Can subscribe my YouTube channel

Share this

2 thoughts on “Using SQL Select Statements”

Leave a Comment