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. " 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. " 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 " 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. " 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

Be the first to post comment on this article :


Post Comment This is for short comments only. Use the forum for more discussions.

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2015 All rights reserved worldwide Privacy Policy Disclaimer