SQL Tutorial: Where Clause

Where---à where clause is used to filter records

Explanation:
Where clause restricts records that is it helps as to apply conditions on SQL statements to get our desired specific records rather than getting all generalized record

Restrict/Limit the returned rows by Where clause

 Three Elements of WHERE Clause:
  1. Column Name
  2. Comparison Operator
  3. Column Name, Constant, List of Values
Example: When you write SELECT SQL statement with * to get records of employees from the employee table you get data from all columns and all rows present in the table of database but the point is sometimes you do not need to know the data of all employees so that makes extra data fetch by SELECT * useless and obviously fetching all data from the table of the database will make database busy from more time period and the database will make the system slow. To eliminate this issue we define “where” clause just after the FROM clause to get specific results without over burden the database.

Consider the example of Employee table. Let’s there be 3 rows in the table.
emp_id
emp_firstname
emp_secondname
emp_address
001
John
smith
Abc
002
Andrew
douglas
Def
003
Jack
Jackson
ghi
 Figure: 1.1

If you execute SELECT statement
Select *
From Employees;

It will display all the 3 records of 3 employees that is the entire table as given in figure 1.1
Select *
From employee
Where emp_id=001;

Now only the data related to employee with emp_id 001 is going to be displayed
emp_id
emp_firstname
emp_secondname
emp_address
001
John
smith
Abc



Comments

Popular posts from this blog

How to Lose Weight: Fast Way of Losing Weight

SQL Tutorial

How to Gain Weight: Drink Milk Shakes