Mark Wilson <[EMAIL PROTECTED]> wrote:
> Two related questions.
> 1. I have a table with a "date" field. (Ex: '04/13/2002'). I want to get a list 
> of all UNIQUE values for that field (many entries from the same day), i.e., all 
> days with entries.
> **************************************
> CREATE TABLE metrics_events_power {
>  mep_id int(11) NOT NULL auto_increment,
>  mep_date text,
>  mep_time time DEFAULT '00:00:00' NOT NULL
> }
> INSERT INTO metrics_events_power VALUES ('1', '04/13/2002', '10:41:19');
> INSERT INTO metrics_events_power VALUES ('1', '04/13/2002', '10:46:19');
> INSERT INTO metrics_events_power VALUES ('1', '04/14/2002', '11:51:19');
> **************************************
> 
> I want a query that returns for this data '04/13/2002' and '04/14/2002'.

Use WHERE clause to set retrieval conditions for rows, f.e WHERE mep_date='04/13/2002' 
OR mep_date='04/14/2002', and GROUP BY mep_date.
Why do you use TEXT column type for the dates? You can use DATE column type and 
DATE_FORMAT() function:
        http://www.mysql.com/doc/en/DATETIME.html
        http://www.mysql.com/doc/en/Date_and_time_functions.html 

> 
> 2. Now I have X tables with those date fields. How do I get a list from all 
> specified tables with the unique dates from them?  For instance, 2 more tables:
> 
> **************************************
> CREATE TABLE arf_events_power {
>  aep_id int(11) NOT NULL auto_increment,
>  aep_date text,
>  aep_time time DEFAULT '00:00:00' NOT NULL
> }
> INSERT INTO arf_events_power VALUES ('1', '05/13/2002', '10:41:19');
> INSERT INTO arf_events_power VALUES ('1', '05/24/2002', '10:46:19');
> INSERT INTO arf_events_power VALUES ('1', '06/21/2002', '11:51:19');
> 
> CREATE TABLE blah_events_power {
>  bep_id int(11) NOT NULL auto_increment,
>  bep_date text,
>  bep_time time DEFAULT '00:00:00' NOT NULL
> }
> INSERT INTO blah_events_power VALUES ('1', '04/13/2002', '10:41:19');
> INSERT INTO blah_events_power VALUES ('1', '04/13/2002', '10:46:19');
> INSERT INTO blah_events_power VALUES ('1', '07/28/2002', '11:51:19');
> **************************************
> 
> Should return 6 dates:
> '04/13/2002'
> '04/14/2002'
> '05/13/2002'
> '05/24/2002'
> '06/21/2002'
> '07/28/2002'

Use UNION:
        http://www.mysql.com/doc/en/UNION.html



-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Egor Egorov
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
       <___/   www.mysql.com




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to