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:

1
SELECT * FROM table_name WHERE column_name_1=somevalue AND column_name_2=somevalue;

Example:

1
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:

1
SELECT * FROM table_name WHERE column_name_1=somevalue OR column_name_2=somevalue

Example:

1
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:

SQL Tutorial – Complete