Hi,
I encountered a problem with a DISTINCT query (mySQL-3.23.42). I need to order by a field not contained in the field set of the SELECT clause. The following query works correctly: SELECT DISTINCT p.lastchanged AS lastchanged, p.dam_id AS dam_id, d.dam AS dam, d.sire1 AS sire1, d.dam1 AS dam1, d.year AS year FROM products p LEFT JOIN dams d ON (p.dam_id=d.dam_id) WHERE p.lastchanged>='$s_from_date' AND p.active='Y' ORDER BY p.lastchanged DESC, d.dam ASC However I don't want to sort by "lastchanged", but by "changed" instead, which has a different meaning than lastchanged in my tables. But now every row shows up several hundred times, instead of being DISTINCTed. SELECT DISTINCT p.lastchanged AS lastchanged, p.dam_id AS dam_id, d.dam AS dam, d.sire1 AS sire1, d.dam1 AS dam1, d.year AS year FROM products p LEFT JOIN dams d ON (p.dam_id=d.dam_id) WHERE p.lastchanged>='$s_from_date' AND p.active='Y' ORDER BY p.changed DESC, d.dam ASC Any idea how I can get this sorted by changed, but correctly DISTINCTed? Regards ... Ralph ... --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php