IN operator. : IN « Function « 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 » Function » IN 
IN operator.
    
mysql>
mysql> CREATE TABLE CDs
    -> (
    ->     CDID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    ->     CDName VARCHAR(50NOT NULL,
    ->     InStock SMALLINT UNSIGNED NOT NULL,
    ->     OnOrder SMALLINT UNSIGNED NOT NULL,
    ->     Reserved SMALLINT UNSIGNED NOT NULL,
    ->     Department ENUM('Classical', 'Popular') NOT NULL,
    ->     Category VARCHAR(20)
    -> );
Query OK, rows affected (0.01 sec)

mysql>
mysql>
mysql> INSERT INTO CDs (CDName, InStock, OnOrder, Reserved, Department, CategoryVALUES
    -> ('Xml', 1053'Popular', 'Rock'),
    -> ('Java', 1053'Classical', 'Opera'),
    -> ('SQL', 1741'Popular', 'Jazz'),
    -> ('MySQL', 942'Classical', 'Dance'),
    -> ('CSS', 2425'Classical', NULL),
    -> ('HTML', 1668'Classical', NULL),
    -> ('Oracle', 2256'Popular', 'Blues'),
    -> ('Javascript', 32310'Popular', NULL),
    -> ('Data type', 121513'Popular', 'Country'),
    -> ('Flash', 52010'Popular', 'New Age'),
    -> ('Ajax', 241114'Popular', 'New Age'),
    -> ('Photoshop', 421717'Classical', NULL),
    -> ('Word', 254428'Classical', 'Dance'),
    -> ('iPhone', 321512'Classical', 'General'),
    -> ('MacBook', 20105'Classical', 'Opera'),
    -> ('Linux', 23128'Classical', 'General'),
    -> ('Shell', 231017'Popular', 'Country'),
    -> ('Pascal', 182010'Popular', 'Jazz'),
    -> ('Ruby', 2257'Popular', 'Blues'),
    -> ('Sql Server', 281716'Classical', 'General'),
    -> ('Opera', 103512'Classical', 'Opera'),
    -> ('Safari', 153014'Popular', NULL),
    -> ('C'4208'Popular', 'Blues'),
    -> ('C++', 1688'Classical', 'General');
Query OK, 24 rows affected (0.00 sec)
Records: 24  Duplicates: 0  Warnings: 0

mysql>
mysql>
mysql>
mysql> SELECT CDName, Category, InStock
    -> FROM CDs
    -> WHERE Category IN ('Blues', 'Jazz')
    -> ORDER BY CDName;
+--------+----------+---------+
| CDName | Category | InStock |
+--------+----------+---------+
| C      | Blues    |      42 |
| Oracle | Blues    |       |
| Pascal | Jazz     |      18 |
| Ruby   | Blues    |      22 |
| SQL    | Jazz     |      17 |
+--------+----------+---------+
rows in set (0.00 sec)

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

   
    
    
    
  
Related examples in the same category
1.The IN() function can be used to test one value against a number of possible values.
2.IN and NOT IN operators provide the most flexibility when comparing values to the results returned by a subque
3.Several different values can be written more easily by using the IN( ) operator.
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.