[英]ORDER BY NOT EXIST in two column from another table. Is it possible?
I have a query ended with ORDER BY NOT EXISTS
.我有一个以
ORDER BY NOT EXISTS
结尾的查询。
I am having an issue with NOT EXISTS
to look at two columns from another table.我遇到
NOT EXISTS
问题,无法查看另一个表中的两列。 The query works with col1
, but not with col2
该查询适用于
col1
,但不适用于col2
FROM
t1
JOIN t2 ON t1.id = t2.id
...
ORDER BY NOT EXISTS
(SELECT col1, col2
FROM t1
WHERE t1.id2 = t2.id2
AND MONTH(t1.date) = MONTH(CURDATE())
) DESC
Ok, Just testing it and found out the solution, that if i use好的,只是测试它并找到了解决方案,如果我使用
WHERE t1.id = t2.id
and instead of而不是
WHERE t1.id2 = t2.id2
it worked.有效。 I told them to look at the current table id
PK
column and not the another table id FK
and it worked.我告诉他们查看当前表 id
PK
列而不是另一个表 id FK
并且它起作用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.