SQL AND OR Operators – SQL TUTORIAL | Software Testing Material
SQL AND OR Operators:
In this post, we will see both SQL AND OR Operators in detail.
SQL ANDÂ Operator:Â It fetches the records only if both the first and the second condition are true.
Syntax:
SELECT * FROMÂ table_name WHERE column_name_1=somevalue AND column_name_2=somevalue;
Example:
SELECT * FROM SCOREBOARD WHERE Playername='Sachin' AND Runs='100';
In the below image, you could see two SELECT queries. First SELECT query returns the complete records from the table SCOREBOARD. Second SELECT query returns only the values where the value in the Playername column is equal to Sachin and value in the Runs column is equal to 100. Both the conditions should become true.
SQL ORÂ Operator: It fetches the records if any one of the condition is true.
Syntax:
SELECT * FROMÂ table_name WHERE column_name_1=somevalue ORÂ column_name_2=somevalue
Example:
SELECT * FROM SCOREBOARD WHERE Playername='Sachin' OR Runs=90;
In the below image, you could see two SELECT queries. First SELECT query returns the complete records from the table SCOREBOARD. Second SELECT query returns only the values where the value in the Playername column is equal to Sachin or value in the Runs column is equal to 90.
In the next tutorial, we will see How To INSERT Data in a Table in SQL
Check out the complete SQL Tutorial by clicking on below link: