Date type value inside in operator and subquery : Date « Data Type « 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 » Data Type » Date 
Date type value inside in operator and subquery
    
mysql>
mysql>
mysql>
mysql> CREATE   TABLE COMMITTEE_MEMBERS
    ->         (EmployeeNO       INTEGER      NOT NULL,
    ->          BEGIN_DATE     DATE         NOT NULL,
    ->          END_DATE       DATE                 ,
    ->          POSITION       CHAR(20)             ,
    ->          PRIMARY KEY    (EmployeeNO, BEGIN_DATE));
Query OK, rows affected (0.00 sec)

mysql>
mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  6'1990-01-01', '1990-12-31', 'Secretary');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  6'1991-01-01', '1992-12-31', 'Member');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  6'1992-01-01', '1993-12-31', 'Treasurer');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  6'1993-01-01',  NULL, 'Chairman');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  2'1990-01-01', '1992-12-31', 'Chairman');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  2'1994-01-01',  NULL, 'Member');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (112'1992-01-01', '1992-12-31', 'Member');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (112'1994-01-01',  NULL, 'Secretary');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  8'1990-01-01', '1990-12-31', 'Treasurer');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  8'1991-01-01', '1991-12-31', 'Secretary');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  8'1993-01-01', '1993-12-31', 'Member');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  8'1994-01-01',  NULL, 'Member');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES 57'1992-01-01', '1992-12-31', 'Secretary');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES 27'1990-01-01', '1990-12-31', 'Member');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES 27'1991-01-01', '1991-12-31', 'Treasurer');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES 27'1993-01-01', '1993-12-31', 'Treasurer');
Query OK, row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES 95'1994-01-01',  NULL, 'Treasurer');
Query OK, row affected (0.00 sec)

mysql>
mysql> SELECT   *
    -> FROM     COMMITTEE_MEMBERS
    -> WHERE   (BEGIN_DATE, END_DATEIN
    ->         (SELECT   BEGIN_DATE, END_DATE
    ->          FROM     COMMITTEE_MEMBERS
    ->          WHERE    POSITION = 'Secretary');
+------------+------------+------------+-----------+
| EmployeeNO | BEGIN_DATE | END_DATE   | POSITION  |
+------------+------------+------------+-----------+
|          1990-01-01 1990-12-31 | Secretary |
|        112 1992-01-01 1992-12-31 | Member    |
|          1990-01-01 1990-12-31 | Treasurer |
|          1991-01-01 1991-12-31 | Secretary |
|         57 1992-01-01 1992-12-31 | Secretary |
|         27 1990-01-01 1990-12-31 | Member    |
|         27 1991-01-01 1991-12-31 | Treasurer |
+------------+------------+------------+-----------+
rows in set (0.00 sec)

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

   
    
    
    
  
Related examples in the same category
1.Date type value in the form '2003-12-31', range 1000-01-01 to 9999-12-31 (3 bytes)
2.To find the row with the most recent birth date, the query is similar, except that you sort in descending orde
3.Compare with Date value
4.How MySQL deals with incorrect date value
5.Date literal in where clause
6.Date value literal
7.Date calculation with variable
8.Date default value
9.Sorting by Calendar Day
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.