【发布时间】:2018-09-27 04:59:23
【问题描述】:
所以在运行下面的查询后,每当我尝试打开受影响的表时,它都会显示“顺序子句中的未知列 doc.section”。我仍然可以在所述表上运行查询,但我无法再使用 phpmyadmin 上的左侧面板访问该表。
查询:
select pending.*
from (
select distinct doc.*, users.dept_id
from list_users users, exit_doc doc
inner join (
select q.section,
max(q.subsection) subsection
from exit_doc q
group by q.section ) latest
on doc.section = latest.section
and doc.subsection = latest.subsection
where doc.user_id = users.user_id) pending
inner join (
select approvers.dept_id, approvers.role_code
from approvers
where user_id = 10004
and delete_flag = 0) user
on pending.next_user = user.role_code
and pending.dept_id = user.dept_id
我的查询是否以某种方式影响了表的结构?错误说 order 子句上的未知列,但我没有在查询中使用任何 order?
【问题讨论】:
-
不要混用显式 JOIN 和隐式逗号分隔的连接。
-
不太明白,能详细点吗?
-
来自 list_users 用户,exit_doc doc - 不好,来自 list_users 用户加入 exit_doc doc on doc.user_id = users.user_id - 更好。
-
用户和文档是两个不同的表,并由名为 latest 的第三个“表”连接
-
您的查询没有
order by,因此它不会产生您提到的错误。