This blog will help you to restrict data from a database.
You can restrict the rows returned from the query by using the WHERE clause. A WHERE clause contains a condition that must be met, and it directly follows the FROM clause. If the condition is true, the row meeting the condition is returned.
Syntax
SELECT *|{[DISTINCT] column|expression [alias],...} FROM table [WHERE condition(s)];
In the syntax:
WHERE restricts the query to rows that meet a condition
condition is composed of column names, expressions, constants, and a comparison operator
The WHERE clause can compare values in columns, literal values, arithmetic expressions, or functions.
Example
SELECT employee_id, last_name, job_id, department_id FROM employees WHERE department_id = 90 ;
This query will fetch the employeeid, lastname, jobid and departmentid of all the employee belongs to department_id 90.
If you want to fetch the details of all the employee whose last name is Joshi.
SELECT * from employees WHERE last_name = 'Joshi' ;
Note:-
1) Character strings and dates in the WHERE clause must be enclosed in single quotation marks ().
2) All character searches are case sensitive.
We can also fetch data by comparing the condition in WHERE clause.
Comparison Conditions
Comparison conditions are used in conditions that compare one expression to another value or
expression. They are used in the WHERE clause in the following format:
Syntax
... WHERE expr operator value
For Example
... WHERE hire_date=01-JAN-95
... WHERE salary>=6000
... WHERE last_name=Joshi
An alias cannot be used in the WHERE clause. Alias is just a "shorthand" name of column or table.
SELECT last_name, salary FROM employees WHERE salary <= 30000;
This query will fetch the last name and salary of all the employees whose salary is less than or equal to 30000.
Hope you like this blog :). In the next blog we will discuss about more operators that we can use with WHERE clause.
Reference:- Oracle docs
0 Comment(s)