SQL PHP HTML ASP JavaScript articles and free scripts to download
 

SELECT WHERE Query with AND OR & NOT combinations

We will try to add AND and OR combination to our SQL SELECT query here. We can get our required requirement by using AND combination. This way we can restrict our records.

You can also read how AND and OR is used in SQL script for MySQL tables

Let us say we are interested in getting records of class Five only.

Here is the query.

rs1.open " SELECT * FROM student WHERE class='Five' " , conn


Now we will collect records of the student of class five who has secured more than 80 marks.

rs1.open " SELECT * FROM student WHERE class='Five' AND mark > 80 " , conn


Now let us try to collect all the records who have secured more than 80 marks. But we will add one more condition . Along with all these records we also want the records of class Four. Here is the query

rs1.open " SELECT * FROM student WHERE class='Four' OR mark > 80 " , conn


Note how we have added two conditions with one OR.

Now let us add one NOT combination to get all the student records who has secured more than 80 mark but we don't want student of class Four.

rs1.open " SELECT * FROM student WHERE NOT(class='Four') AND mark > 80 " , conn


You can read the record display and download the structure and csv file for student table here





Join Our Email List
Email:  
For Email Newsletters you can trust
MSSQL Query
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2013 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer