Was trying to implement this snippet on a customized homepage for "authenticated users" using the Advanced Frontpage module. But keep getting the same error, both with and without the suggested addition to the sql (in the comments of the snippet).
The sql from the snippet is:
SELECT distinct n.title, n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid in ($terms) AND n.status=1 ORDER BY n.created DESC
or
SELECT n.title, n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid in ($terms) AND n.status=1 ORDER BY n.created DESC
Both create the same problem....
The sql sent to the db by Drupal is:
SELECT distinct n.title, DISTINCT(n.nid) FROM tot_node n INNER JOIN tot_term_node tn ON n.nid = tn.nid WHERE tn.tid in (14,15,16,17,18,19,20) AND n.status=1 ORDER BY n.created DESC LIMIT 0, 10
Looks like the core Drupal db function _db_rewrite_sql has automatically determined to insert the DISTINCT() around n.nid, which apparently makes this invalid syntax(?).
The actual error message I get when i try to save the snippet inside my custom homepage is this: