The SQL AND and OR operators are used to combine multiple conditions to narrow data in an SQL statement. These two operators are called conjunctive operators.
These operators provide a means to make multiple comparisons with different operators in the same SQL statement.
AND OPERATOR:
can combine N number of conditions using AND operator. For an action to be taken by the SQL statement, whether it be a transaction or query, all conditions separated by the AND must be TRUE.
OR OPERATOR:
can combine N number of conditions using OR operator. For an action to be taken by the SQL statement, whether it be a transaction or query, only any ONE of the conditions separated by the OR must be TRUE.
SYNTAX:
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION-1 {AND|OR} CONDITION-2;
EXAMPLE:
SELECT no,name from student where result='pass' and class='first';
Displays the columns no,name from the table student where result=pass and class=first.
SELECT * from student where class='first' OR class='second';
Displays all the column values having class=first or class=second.
No comments:
Post a Comment