Database Concept
DBMS ER Model
DBMS Relational model
- DBMS Codd’s 12 rule
- DBMSBasic Concepts
- DBMS Relational Algebra
- DBMS Relational Calculus
- DBMS ER Model to Relational Model
- DBMS Types of Database key
DBMS Normalization
- DBMS Introduction to Normalization
- DBMS First Normal Form (1NF)
- DBMS Second Normal Form (1NF)
- DBMS Third Normal Form (3NF)
- DBMS Boyce-Codd Normal Form (BCNF)
- DBMS Fourth Normal Form (4NF)
- DBMS Fifth Normal Form (5NF)
DBMS Basic SQL
DBMS DML Command
DBMS DCL Command
- All DCL Command
- SELECT query
- WHERE clause
- LIKE clause
- ORDER BY clause
- Group BY clause
- Having clause
- DISTINCT keyword
- AND & OR operator
- DIVISION operator
Advanced SQL
The AND
and OR
operators are used with the WHERE
clause to make more precise conditions for fetching data from database by combining more than one condition together.
AND
operator
AND
operator is used to set multiple conditions with the WHERE
clause, alongside, SELECT
, UPDATE
or DELETE
SQL queries.
Example of AND
operator
Consider the following Emp table
eid | name | age | salary |
---|---|---|---|
401 | Anu | 22 | 5000 |
402 | Shane | 29 | 8000 |
403 | Rohan | 34 | 12000 |
404 | Scott | 44 | 10000 |
405 | Tiger | 35 | 9000 |
SELECT * FROM Emp WHERE salary < 10000 AND age > 25
The above query will return records where salary is less than 10000 and age greater than 25. Hope you get the concept here. We have used the AND
operator to specify two conditions with WHERE
clause.
eid | name | age | salary |
---|---|---|---|
402 | Shane | 29 | 8000 |
405 | Tiger | 35 | 9000 |
OR
operator
OR
operator is also used to combine multiple conditions with WHERE
clause. The only difference between AND
and OR
is their behaviour.
When we use AND
to combine two or more than two conditions, records satisfying all the specified conditions will be there in the result.
But in case of OR
operator, atleast one condition from the conditions specified must be satisfied by any record to be in the resultset.
Example of OR
operator
Consider the following Emp table
eid | name | age | salary |
---|---|---|---|
401 | Anu | 22 | 5000 |
402 | Shane | 29 | 8000 |
403 | Rohan | 34 | 12000 |
404 | Scott | 44 | 10000 |
405 | Tiger | 35 | 9000 |
SELECT * FROM Emp WHERE salary > 10000 OR age > 25
The above query will return records where either salary is greater than 10000 or age is greater than 25.
402 | Shane | 29 | 8000 |
403 | Rohan | 34 | 12000 |
404 | Scott | 44 | 10000 |
405 | Tiger | 35 | 9000 |