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

Further readings
SELECT query in collecting records from MSSQL table
TOP with SELECT query to collect number of records
SELECT query with AND OR NOT for MSSQL table
SELECT query with LIKE using wildcards % and _
Count: Counting total records in MSSQL table
Group By: SQL command in MSSQL table
Different Date & Time formats by using Convert in SELECT query
 
Scripts
PHP
JavaScript
All ASP Tutorials
SELECT Query
SELECT
AND OR NOT
count
Date formats
Group By
LIKE & _
TOP
ASP Sections
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
String Functions
Popular Tutorials
Managing two drop downs
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.