AND & OR Syntax for SELECT Query in Mysql

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
Column_name1Column_name2Column_name3Column_name4
1MalearticlesSam
2FemaledatabaseSam
3MalecodingJam
4MalecodingKam
5FemalecodingJam

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 


table_name
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



table_name
Column_name1 Column_name2 Column_name3 Column_name4
1 Male articles Sam
3 Male coding Jam
4 Male coding Kam
5 Female coding Jam


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
Column_name1 Column_name2 Column_name3 Column_name4
1 Male articles Sam

Comments

Popular posts from this blog

Five More Indian Languages - Google Translate