Reversing or Negating Query Conditions : Operator « Select Clause « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Select Clause » Operator 
Reversing or Negating Query Conditions
      
mysql>
mysql> CREATE TABLE mail
    -> (
    ->  t               DATETIME,       # when message was sent
    ->  senderUser      CHAR(8),        # sender (source user and host)
    ->  senderHost      CHAR(20),
    ->  recipientUser   CHAR(8),        # recipient (destination user and host)
    ->  recipientHost   CHAR(20),
    ->  size    BIGINT,         # message size in bytes
    ->  INDEX   (t)
    -> );
Query OK, rows affected (0.00 sec)

mysql>
mysql> INSERT INTO mail (t,senderHost,senderUser,recipientHost,recipientUser,size)
    ->  VALUES
    ->          ('2010-05-11 10:15:08','saturn','barb','mars','tricia',58274),
    ->          ('2010-05-12 12:48:13','mars','tricia','venus','gene',194925),
    ->          ('2010-05-12 15:02:49','mars','phil','saturn','phil',1048),
    ->          ('2010-05-13 13:59:18','saturn','barb','venus','tricia',271),
    ->          ('2010-05-14 09:31:37','venus','gene','mars','barb',2291),
    ->          ('2010-05-14 11:52:17','mars','phil','saturn','tricia',5781),
    ->          ('2010-05-14 14:42:21','venus','barb','venus','barb',98151),
    ->          ('2010-05-14 17:03:01','saturn','tricia','venus','phil',2394482),
    ->          ('2010-05-15 07:17:48','mars','gene','saturn','gene',3824),
    ->          ('2010-05-15 08:50:57','venus','phil','venus','phil',978),
    ->          ('2010-05-15 10:25:52','mars','gene','saturn','tricia',998532),
    ->          ('2010-05-15 17:35:31','saturn','gene','mars','gene',3856),
    ->          ('2010-05-16 09:00:28','venus','gene','mars','barb',613),
    ->          ('2010-05-16 23:04:19','venus','phil','venus','barb',10294),
    ->          ('2010-05-17 12:49:23','mars','phil','saturn','tricia',873),
    ->          ('2010-05-19 22:21:51','saturn','gene','venus','gene',23992)
    -> ;
Query OK, 16 rows affected (0.00 sec)
Records: 16  Duplicates: 0  Warnings: 0

mysql>
mysql>
mysql> SELECT FROM mail WHERE senderUser != recipientUser;
+---------------------+------------+------------+---------------+---------------+---------+
| t                   | senderUser | senderHost | recipientUser | recipientHost | size    |
+---------------------+------------+------------+---------------+---------------+---------+
2010-05-11 10:15:08 | barb       | saturn     | tricia        | mars          |   58274 |
2010-05-12 12:48:13 | tricia     | mars       | gene          | venus         |  194925 |
2010-05-13 13:59:18 | barb       | saturn     | tricia        | venus         |     271 |
2010-05-14 09:31:37 | gene       | venus      | barb          | mars          |    2291 |
2010-05-14 11:52:17 | phil       | mars       | tricia        | saturn        |    5781 |
2010-05-14 17:03:01 | tricia     | saturn     | phil          | venus         | 2394482 |
2010-05-15 10:25:52 | gene       | mars       | tricia        | saturn        |  998532 |
2010-05-16 09:00:28 | gene       | venus      | barb          | mars          |     613 |
2010-05-16 23:04:19 | phil       | venus      | barb          | venus         |   10294 |
2010-05-17 12:49:23 | phil       | mars       | tricia        | saturn        |     873 |
+---------------------+------------+------------+---------------+---------------+---------+
10 rows in set (0.00 sec)

mysql>
mysql> drop table mail;
Query OK, rows affected (0.00 sec)

   
    
    
    
    
    
  
Related examples in the same category
1.Comparison Operators
2.Comparison operators 2
3.Arithmetic Operators
4.Sort Operators
5.special <=> operator, which is like = except that it works with NULL operands by treating them as any other va
6.Compare NULL with <=> operator
7.Not operator
8.or operator vs in operator
9.Comparison Operators and null
10.Use the basic mathematical operators
11.In operator and a long list of integer
12.Less than and equals(<=) operators with All operator
13.Not equal
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.