I am having a problem building a SELECT statement that joins two tables with a WHERE condition.


SELECT trucks.*

FROM
        trucks, history

WHERE
trucks.account_id = '100'
AND trucks.status = 'Active'
AND history.truck_id = trucks.id <<<< This is the tricky bit


GROUP BY
        trucks.id

ORDER BY
        history.time_sec DESC


Simply put (or as simply as I can put it :-) , this SELECT should return all trucks in order of their activity (history.time_sec). The problem is when a truck is new to the system and does not have a single record in the history table (and therefore no value for history.time_sec). In that case, the truck is excluded from the SELECTed rows—but I want it returned, just at the bottom of the list (least active).


Any ideas how this can be done?

...Rene

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



Reply via email to