Hi! Note MySQL version: 3.23.33 I need to sort sql query results in a complex way. If you could please help it would be much appreciated. Thanks in advance! I have 7 tables: 1 is a base table then 3 pairs of list and joiner tables 2,3; 4,5; and 6,7 where 2,4 and 6 are joiners between 1 and the list tables 3,4 and 5. I need to create an sql query to 1) Order by the number of joins in joiner tables 2 and 4, then number of joins in table 6. 2) return only distinct rows from table 1 3) secondarily ordered by field in table 1. e.g. query SELECT tab1.* FROM tab1,tab2,tab3,tab4,tab5,tab6,tab7 WHERE tab1.keyfield=tab2.keyfield AND tab2.listfield=tab3.listfield AND tab1.keyfield=tab4.keyfield AND tab4.listfield=tab5.listfield AND tab1.keyfield=tab6.keyfield AND tab6.listfield=tab7.listfield AND (tab3.listfield='teststring' OR tab5.listfield='teststring' OR tab7.listfield='teststring' ...) GROUP BY tab1.field1 ORDER BY [??? COUNT(tab4.keyfield,tab6.keyfield), COUNT(tab2.keyfield), tab1.field2 ???] Paul --------------------------------------------------------------------- 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