order子句中的'task_id'列不明确

时间:2014-03-31 02:25:29

标签: mysql sql

    SELECT a.*, p.*, t.*, r.*, n.* 
FROM prop_assigns AS a 
LEFT JOIN properties AS p 
ON (p.property_id = a.property_id)
 LEFT JOIN tasks AS t ON (t.task_id = a.task_id)
 LEFT JOIN reminders_tasks AS r ON (a.assign_id = r.assign_id)
 LEFT JOIN notes_view AS n ON (p.property_id = n.property_id)
 WHERE a.user_id = 3 AND a.task_id <> 0 AND
 a.assign_done = 0 AND n.user_id = 3 ORDER BY task_id desc

MySQLarépondu:文档

#1052 - Column 'task_id' in order clause is ambiguous

它看起来很长sql任何帮助

1 个答案:

答案 0 :(得分:3)

字段task_id位于多个表中。您需要指定您的意思:

SELECT a.*, p.*, t.*, r.*, n.*
FROM prop_assigns AS a LEFT JOIN
     properties AS p
     ON (p.property_id = a.property_id) LEFT JOIN
     tasks AS t
     ON (t.task_id = a.task_id) LEFT JOIN
     reminders_tasks AS r
     ON (a.assign_id = r.assign_id) LEFT JOIN
     notes_view AS n
     ON (p.property_id = n.property_id)
WHERE a.user_id = 3 AND a.task_id <> 0 AND a.assign_done = 0 AND n.user_id = 3
ORDER BY t.task_id desc;
---------^