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.


SELECT
	employee_id,
	first_name,
	last_name,
	department_id
FROM
	hr.employees;
   

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.


SELECT
	employee_id,
	first_name,
	last_name,
	department_id
FROM
	hr.employees
WHERE
	department_id = 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..

DUAL TABLE

Oracle_DUAL table

Hey geeks, DUAL table is a very important table available in the Oracle database. It gets created automatically during the […]

Concatenation Operator

Oracle_Concatenation Operator

Hey geeks, This is another chapter of Operators. Concatenation Operator helps to concatenate two or more strings or columns. The […]

Parentheses

Parentheses in SQL

Hey time travellers, Though Parentheses are used pretty much everywhere in SQL but in this blog, we will talk about […]

Leave a Reply

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