-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday 10 September 2004 18:00, René Fournier wrote: > I've got a SELECT statement that is returning the data I want, but not > in the right order (and I don't know why...). Let's say there are two > tables, People and History. Some records in People have corresponding > records in History, but not all--so I need a LEFT JOIN TO connect > history.people_id to people.id. So far, so good. But I want to order > the list according to the timestamp column in history > (history.time_sec), and this does not happen: Records are returned, but > not in the right order. Here's my query: > > SELECT * > FROM people > LEFT JOIN history ON people.id = history.people_id > GROUP BY people.id > ORDER BY history.time_sec DESC > > It seems I can sort correctly on a field in people, but not on a field > in history—is that because it is a left-joined table?
I think it's because you're trying to sort on missing data. How can it sort on a field that isn't always there? Remember NULL doesn't compare as less than, equal *OR* greater than another value. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFBQjZljeziQOokQnARAidWAJ9zr+/x6EWJ8xTYCsmbvQVy5gMOIACgku3v KGWramLsfIBe7zwm8csGvwM= =hRZV -----END PGP SIGNATURE----- -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]