select title,id from label where project_id = 42 and `status` = 1 and type = 0 order by id a inner join select title,id from label a where project_id = 42 and `status` = 1 and type = 4 order by listorder b on a.title = b.title
时间: 2023-12-14 14:39:15 浏览: 90
这是一条 SQL 查询语句,目的是从一个名为 "label" 的表中获取项目ID为42、类型为0、状态为1的标签的标题和ID,同时按照ID排序;然后将结果与另一个项目ID为42、类型为4、状态为1的标签按照指定顺序排序后的标题和ID进行内连接(即只返回两个表中都有的记录),并且连接条件是这两个表中的标签标题相同。
但是,该查询语句存在语法错误,应该将 "order by id" 和 "inner join" 中间的 "a" 删除。正确的查询语句如下:
```
select a.title, a.id from label a inner join
(select title, id from label where project_id = 42 and `status` = 1 and type = 4 order by listorder) b
on a.title = b.title
where a.project_id = 42 and a.status = 1 and a.type = 0
order by a.id
```
阅读全文