[thelist] SQL ORDER BY question

Jay Blanchard jay.blanchard at niicommunications.com
Thu Aug 22 10:14:01 CDT 2002


Good morning guru group!

I have a log table

+----+----------------+------------+---------------+------+
| ai |       id       |  logDate   |   logEntry    | lgHr |
+----+----------------+------------+---------------+------+
|  1 | PPT20020719TJB | 2002-07-15 | Completed ... | 2.25 |
|  2 | PPT20020719TJB | 2002-07-15 | Did this .... | 1.75 |
|  3 | PPT20020719TJB | 2002-07-18 | Repaired .... | 0.25 |
+----+----------------+------------+---------------+------+

SO, I;

SELECT ai, logDate, logEntry, lgHr
FROM projectlog
WHERE id = 'PPT20020719TJB'
ORDER BY logDate DESC

Which returns;
+----+----------------+------------+---------------+------+
| ai |       id       |  logDate   |   logEntry    | lgHr |
+----+----------------+------------+---------------+------+
|  3 | PPT20020719TJB | 2002-07-18 | Repaired .... | 0.25 |
|  1 | PPT20020719TJB | 2002-07-15 | Completed ... | 2.25 |
|  2 | PPT20020719TJB | 2002-07-15 | Did this .... | 1.75 |
+----+----------------+------------+---------------+------+

which is OK, but I would like to return;

+----+----------------+------------+---------------+------+
| ai |       id       |  logDate   |   logEntry    | lgHr |
+----+----------------+------------+---------------+------+
|  3 | PPT20020719TJB | 2002-07-18 | Repaired .... | 0.25 |
|  2 | PPT20020719TJB | 2002-07-15 | Did this .... | 1.75 |
|  1 | PPT20020719TJB | 2002-07-15 | Completed ... | 2.25 |
+----+----------------+------------+---------------+------+

Which is last in, first out BY DATE. But doing ORDER BY logDate, ai DESC or
ORDER BY ai, logDate DESC will not return the desired results either. I have
searched the web for ORDER BY information, cannot find what I am looking
for. I would prefer to handle this in the SQL instead of programatically.
What am I (aside from 75% of my brain) missing?

TIA!

Jay

***********************************************************
* Texas PHP Developers Conf  Spring 2003                  *
* T Bar M Resort & Conference Center                      *
* New Braunfels, Texas                                    *
* San Antonio Area PHP Developers Group                   *
* Interested? Contact jay.blanchard at niicommunications.com *
***********************************************************





More information about the thelist mailing list