SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

SQL AND OR in WHERE query Commands and statements

SQL AND OR statement can be used with WHERE clause to list a set of  records with matching combination of a table. We can use AND OR SQL in query with NOT  combination also to filter out some records.    This is our table

id name class mark
1 John Deo Four 75
2 Max Ruin Three 85
3 Arnold Three 55
4 Krish Star Four 60
5 John Mike Four 60
6 Alex John Four 55
7 My John Rob Fifth 78
 
We will apply AND  command to display records of class Four with more than 70 mark.
SELECT * FROM student WHERE class='Four' AND mark >70
id name class mark
1 John Deo Four 75
 WE can see the record returned is class= Four and mark is more than 70. Here both the conditions are satisfied. 
SELECT * FROM student WHERE class='Four' OR mark >70
id name class mark
1 John Deo Four 75
2 Max Ruin Three 85
4 Krish Star Four 60
5 John Mike Four 60
6 Alex John Four 55
7 My John Rob Fifth 78
Here the records returned are either belongs to class Four OR having mark more than 70. Any one of the two condition is to be satisfied.

Discuss this tutorial at forum

List of SQL Tutorials


 
Scripts
PHP
JavaScript
HOME
SQL Tutorial List
SQL (Home)
SQL Commands
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.