H I O X INDIA
MySQL Tutorial
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Mysql Tutorial
Introduction
How to Install
Database
Datatypes
Tables
INSERT
SELECT
UPDATE
DELETE
Operators
Functions
Ask Your Doubts
Feedback





Logical Operators


Topic

How to select data from MySQL using Logical Operators?
How to use logical operator in MySQL?
What are the logical operations?



Explanation


Logical Operator :

    MySQL supports the following logical operations :



AND(&&) Operator :

    The logical AND(&&) operator indicates whether the both operands are true. Lets see a statement using AND operator.

mysql> select studid, name from student where marks > 80 
and marks < 100;
                            (or)
mysql> select studid, name from student where marks > 80 
&& marks < 100;
+--------+-------+
| studid | name  |
+--------+-------+
|      4 | jack  |
|      8 | mille |
+--------+-------+
2 rows in set (0.00 sec)
    In the above example it will list the studid and name of the student who have secured more than 80 and less than 100.

OR(||) Operator :

    The logical OR(||) operator indicates whether either operand is true. Lets see a statement using OR operator.

mysql> select name, marks, address from student where 
name like 'a%' or name like 's%';
				(or)
mysql> select name, marks, address from student where 
name like 'a%' || name like 's%';
+-------+-------+------------------+
| name  | marks | address          |
+-------+-------+------------------+
| steve |   100 | 5th cross street |
| anne  |   100 | downing street   |
| steve |    75 | downing street   |
| anne  |    80 | edinburgh        |
+-------+-------+------------------+
4 rows in set (0.00 sec)
    In the above statement it will list the name, marks and address of the student whose name starts with the letter A and S.

NOT(!) Operator :

    The logical NOT(!) operator have only one operand and it returns the inverse of the value.

mysql> select * from student where not (studid=1);
				(or)
mysql> select * from student where ! (studid=1);
+--------+-------+-------+-----------------+---------+
| studid | name  | marks | address         | phone   |
+--------+-------+-------+-----------------+---------+
|      2 | david |   100 | welling street  |  547896 |
|      4 | jack  |    82 | welling street  | 2436821 |
|      5 | anne  |   100 | downing street  | 2634821 |
|      6 | steve |    75 | downing street  | 2874698 |
|      7 | anne  |    80 | edinburgh       | 2569843 |
|      8 | mille |    98 | victoria street | 1236547 |
+--------+-------+-------+-----------------+---------+
6 rows in set (0.00 sec)
    It will list all the student details except the studid 1.



others


        MySQL is the most popular open source database Management system. Being a open source anyone can use and change the software for their needs. Hope you enjoy this tutorial. We welcome your Valuable feedbacks or suggestions on this MySQL tutorial. This is a copyright content.


privacy policy     license     sitemap
© 2004-2005 HIOX INDIA - hioxindia.com

Other Links