OK - Sorry. When users call, Forums, unfortunately, get put on hold.
So, here's a little data for you about DISTINCT.
NOTE I use MySQL, so some of the commands are a little different in Access.
Code:
CREATE TABLE `test1` (
`id` int(10) unsigned NOT NULL auto_increment,
`SubmDate` date default NULL,
`status` varchar(45) default 'undefined',
`flag` tinyint(3) unsigned default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO test1 (SubmDate) VALUES
('2007-10-04'),
('2007-10-05'),
('2007-10-06'),
('2007-10-07'),
('2007-10-07'),
('2007-10-08'),
('2007-10-08'),
('2007-10-09'),
('2007-10-10'),
('2007-10-11'),
('2007-10-11')
SELECT DISTINCT ID, SubmDate FROM test1;
+----+------------+
| ID | SubmDate |
+----+------------+
| 1 | 2007-10-04 |
| 2 | 2007-10-05 |
| 3 | 2007-10-06 |
| 4 | 2007-10-07 |
| 5 | 2007-10-07 |
| 6 | 2007-10-08 |
| 7 | 2007-10-08 |
| 8 | 2007-10-09 |
| 9 | 2007-10-10 |
| 10 | 2007-10-11 |
| 11 | 2007-10-11 |
+----+------------+
SELECT DISTINCT(SubmDate),ID FROM test1;
+------------+----+
| SubmDate | ID |
+------------+----+
| 2007-10-04 | 1 |
| 2007-10-05 | 2 |
| 2007-10-06 | 3 |
| 2007-10-07 | 4 |
| 2007-10-07 | 5 |
| 2007-10-08 | 6 |
| 2007-10-08 | 7 |
| 2007-10-09 | 8 |
| 2007-10-10 | 9 |
| 2007-10-11 | 10 |
| 2007-10-11 | 11 |
+------------+----+
Do the two queries above look familiar?? You will also notice that the results look the same, too.
So, let's update 2 records, just to have a little fun...
Code:
UPDATE test1 SET Status = 'defined', flag = 1 WHERE ID = 4;
UPDATE test1 SET Status = 'defined', flag = 1 WHERE ID = 10;
SELECT DISTINCT ID,SubmDate,Status,flag FROM test1;
+----+------------+-----------+------+
| ID | SubmDate | Status | flag |
+----+------------+-----------+------+
| 1 | 2007-10-04 | undefined | 0 |
| 2 | 2007-10-05 | undefined | 0 |
| 3 | 2007-10-06 | defined | 1 |
| 4 | 2007-10-07 | undefined | 0 |
| 5 | 2007-10-07 | undefined | 0 |
| 6 | 2007-10-08 | undefined | 0 |
| 7 | 2007-10-08 | undefined | 0 |
| 8 | 2007-10-09 | undefined | 0 |
| 9 | 2007-10-10 | undefined | 0 |
| 10 | 2007-10-11 | defined | 1 |
| 11 | 2007-10-11 | undefined | 0 |
+----+------------+-----------+------+
Hmm... No change. Why? DISTINCT looks at all rows and all columns in the SELECT.
Now:
Code:
SELECT DISTINCT SubmDate FROM test1 WHERE flag=0 and `status`='undefined';
+------------+
| SubmDate |
+------------+
| 2007-10-04 |
| 2007-10-05 |
| 2007-10-07 |
| 2007-10-08 |
| 2007-10-09 |
| 2007-10-10 |
| 2007-10-11 |
+------------+
That works, but we only retrieved the Submission Date (SubmDate), not the ID.
Now, try this...:
Code:
SELECT ID, SubmDate FROM test1 WHERE `status`='undefined' AND flag=0 GROUP BY SubmDate;
+----+------------+
| ID | SubmDate |
+----+------------+
| 1 | 2007-10-04 |
| 2 | 2007-10-05 |
| 4 | 2007-10-07 |
| 6 | 2007-10-08 |
| 8 | 2007-10-09 |
| 9 | 2007-10-10 |
| 11 | 2007-10-11 |
+----+------------+
Gets you the records you want, without DISTINCT!!
Let me know if you have any other questions on DISTINCT or the GROUP BY clause.