SQL – WHERE clause

WHERE

admin DataBase, Oracle ,

Hi DBgeek Army,
Welcome back to the world of Oracle!
Where clause helps to select desired rows or helps to limit the number of rows returned by the SELECT statement. If we omit this clause in the query, Oracle performs the action for all the rows available in the Table specified in the query.
For example, if there is a SELECT statement, it will show all the records from the Table or if there there is an UPDATE statement, Oracle will update all the records available in the Table.
It is pretty easy to apply in the sql query. See the syntax below.

Syntax:

sql_query WHERE conditions;

We just need to add keyword WHERE and a valid condition on the basis of what we want as an output.

Let’s select the Employees table of HR schema without WHERE clause.

Below table is showing only a few rows out of Employees Table but when you run it on your own System you will see all 107 records.

EMPLOYEE_IDFIRST_NAMELAST_NAMEDEPARTMENT_ID
100StevenKing90
101NeenaKochhar90
102LexDe Haan90
103AlexanderHunold60
104BruceErnst60
105DavidAustin60
106ValliPataballa60
107DianaLorentz60
108NancyGreenberg100
109DanielFaviet100

Let’s select the same table once again with WHERE clause and in the output, we just want those Employees whose Department_id is 100.

When you run above SQL statement, you will see only those Employees whose Department_id is 100

EMPLOYEE_IDFIRST_NAMELAST_NAMEDEPARTMENT_ID
108NancyGreenberg100
109DanielFaviet100
110JohnChen100
111IsmaelSciarra100
112Jose ManuelUrman100
113LuisPopp100

You can see DEPARTMENT_ID in the above table. All selected records have DEPARTMENT_ID as 100.

You can check UPDATE to understand how important WHERE clause is.

If you have any questions/suggestions, please comment below or write me an email.
If you like this blog, do share with your friends and colleagues on your social media.
For more updates join my facebook group and do like my facebook page.

Thank you,
Kapil Kumar
dbgeek.in

Sharing is caring!

You May Also Like..

NULLIF

Oracle SQL_Null Related functions-3_NULLIF

Hi Aliens, Today, we will talk about another Null Related Function, NULLIF. You can read my notes on NVL, NVL2 […]

comments

Comment in SQL and PL-SQL

Hi DBgeek Army, Welcome back to the world of Oracle! Comments are very important aspects of our code. No matter […]

Pseudocolumn - ORA_ROWSCN

Pseudocolumn – ORA_ROWSCN

Hi DBgeek Army, Welcome back to the world of Oracle! Today, we will talk about Pseudocolumn. Oh, wait. Have you […]

Leave a Reply

Your email address will not be published. Required fields are marked *