SQL - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SQL And-Or Clauses

SQL And-Or Clauses

shape Description

The SQL AND-OR Clauses functions are utilized to consolidate various conditions to slender information in a SQL articulation. These two functions are called conjunctive operators. These operations contribute a way to make various correlations with various operations in the same SQL explanations.For understanding sql And-or clause first the user need to understand about Where Clause

SQL And Operator

shape Description

To specify multiple conditions in SQL command use AND operators.

shape Syntax

The syntax for AND operator is as follows:
Select * from table name where <condition1> AND <condition2> AND .....<conditionN>; Table => Accurate table in the database. Conditions => Logical operations.

shape Examples

By viewing the below example the concept of SQL AND operator an be easily understood. [c] SQL>Select * from Employee; +----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Mike | 32 | Texas | 2000 | | 2 | James | 25 | New York | 1500 | | 3 | Jack | 23 | Edmond | 2000 | | 4 | Maddie | 25 | Washington| 6500 | | 5 | Wiston | 27 | Villas | 8500 | | 6 | Mack | 22 | Swiss | 4500 | | 7 | Muffy | 24 | Indore | 10000 | +----+----------+-----+-----------+----------+ 7 rows in set (0.00 sec) SQL> SELECT ID, NAME, SALARY FROM Employee WHERE SALARY > 2000 AND age SELECT ID, NAME, SALARY FROM Employee WHERE SALARY > 6500 AND age > 23; +----+-------+----------+ | ID | NAME | SALARY | +----+-------+----------+ | 5 | Wiston| 8500.00 | | 7 | Muffy | 10000.00 | +----+-------+----------+ 2 rows in set (0.00 sec) [/c] Here in the above example specific values can be retrieved by using AND operator.

SQL Or Operator

shape Description

The OR operator is used to combine multiple conditions in an SQL statement.

shape Syntax

The syntax for OR operator is as follows:
Select * from table name where <condition1> OR <condition2> OR .....<conditionN>; Table => Accurate table in the database. Conditions => Logical operations.

shape Examples

By viewing the below example the concept of SQL OR operator can be easily understood. [c] SQL>Select * from Employee; +----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Mike | 32 | Texas | 2000 | | 2 | James | 25 | New York | 1500 | | 3 | Jack | 23 | Edmond | 2000 | | 4 | Maddie | 25 | Washington| 6500 | | 5 | Wiston | 27 | Villas | 8500 | | 6 | Mack | 22 | Swiss | 4500 | | 7 | Muffy | 24 | Indore | 10000 | +----+----------+-----+-----------+----------+ 7 rows in set (0.00 sec) SQL> SELECT ID, NAME, SALARY FROM Employee WHERE SALARY > 2000 OR age < 25; +----+----------+----------+ | ID | NAME | SALARY | +----+----------+----------+ | 3 | Jack | 2000 | | 4 | Maddie | 6500 | | 5 | Wiston | 8500 | | 6 | Mack | 4500.00 | | 7 | Muffy | 10000.00 | +----+----------+----------+ 5 rows in set (0.00 sec)[/c] Here in the above example multiple values can be retrieved by using OR operator.

Summary

shape "Key

  • SQL And-Or Clauses - Are utilized to consolidate various conditions to slender information in a SQL articulation.
  • SQL AND Operator - Used to specify multiple conditions in SQL statement.
  • SQL OR Operator - Used to combine multiple conditions in SQL statements.