SQL WHERE


SQL WHERE Statement

In this tutorial post, we are going to discussing SQL WHERE statement in oracle data base. Oracle provides the option of using WHERE statement in an SQL query to apply a filter on the rows retrieved.

When a WHERE clause is added to the SQL query, then query executing as follows.

  • The Oracle engine compares each record in the table with the condition specified in the WHERE clause.
  • The Oracle engine displays only those records that satisfy the specified condition.

Consider we have EMPLOYEE demo table which is using for the executing WHERE command.

EMP_ID EMP_NAME EMP_DESIGNATION EMP_GENDER EMP_QUALIFICATION EMP_LOCATION
100 Narayanaswamy Sr.Software Engineer Male MCA Chennai
101 Kumar Quality Analyst Male B.Tech Chennai
102 Ramesh Database Administration Male B.Tech Chennai

Filtering Table Data

The ways of filtering table data are:

 

Selected columns and all columns

By using SELECT statement we can achieve above criteria. Click here to see the article.

 

Selected rows and all columns

By using WHERE statement we can achieve above criteria as follows.

Syntax:

SELECT * FROM <Table-Name> WHERE <Condition>;

Here <Condition> is always quantified as <Column-Name = Column-Value>

Query:

SELECT * FROM EMPLOYEE WHERE EMP_ID=100;

It will return all columns and selected rows result set data from the table as below.

EMP_ID EMP_NAME EMP_DESIGNATION EMP_GENDER EMP_QUALIFICATION EMP_LOCATION
100 Narayanaswamy Sr.Software Engineer Male MCA Chennai

 

Selected columns and selected columns

By using WHERE statement we can achieve above criteria as follows.

Syntax:

SELECT <Column-Name 1>,<Column-Name 2> FROM <Table-Name> WHERE <Condition>;

Here <Condition> is always quantified as <Column-Name = Column-Value>

Query:

SELECT EMP_ID,EMP_NAME FROM EMPLOYEE WHERE EMP_ID=100;

It will return selected columns EMP_ID, EMP_NAME and selected rows where EMP_ID=100, result set data from the table as below.

EMP_ID EMP_NAME
100 Narayanaswamy

Leave a Reply