AND & OR Syntax in Select Query can be used to filter the data from table column with multiple choices.
AND Syntax will show results only when both conditions are true but
OR Syntax will show results even when one condition is true.
Example Table : For your reference
table_name
AND Syntax Example
table_name
OR Syntax Example
table_name
AND & OR Syntax Example
Query : "SELECT * from table_name WHERE Column_name4='Sam' AND (Column_name3='articles' OR Column_name3='coding') "
If you execute the above query then its mandatory to have Column_name4 with Sam data but for Column_name3 can have articles or coding
table_name
AND Syntax will show results only when both conditions are true but
OR Syntax will show results even when one condition is true.
Example Table : For your reference
table_name
Column_name1 | Column_name2 | Column_name3 | Column_name4 |
1 | Male | articles | Sam |
2 | Female | database | Sam |
3 | Male | coding | Jam |
4 | Male | coding | Kam |
5 | Female | coding | Jam |
Table Name is : table_name
AND Syntax Example
Query : "SELECT * from table_name WHERE Column_name3='articles' AND Column_name4='Sam'"
If you execute the above query then the first record will appear
Column_name1 | Column_name2 | Column_name3 | Column_name4 |
1 | Male | articles | Sam |
OR Syntax Example
Query : "SELECT * from table_name WHERE Column_name3='articles' OR Column_name3='coding'"
If you execute the above query then the records which contains coding and articles from column_name3 will be displayed
Column_name1 | Column_name2 | Column_name3 | Column_name4 |
1 | Male | articles | Sam |
3 | Male | coding | Jam |
4 | Male | coding | Kam |
5 | Female | coding | Jam |
Query : "SELECT * from table_name WHERE Column_name4='Sam' AND (Column_name3='articles' OR Column_name3='coding') "
If you execute the above query then its mandatory to have Column_name4 with Sam data but for Column_name3 can have articles or coding
table_name
Column_name1 | Column_name2 | Column_name3 | Column_name4 |
1 | Male | articles | Sam |
Comments
Post a Comment