简体   繁体   English

ORDER BY NOT EXIST 在另一个表的两列中。 是否可以?

[英]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.

相关问题 我尝试加入两个表,但另一个表名在第一个表的列中。 是否可以加入或是否有 - I try to join two table but another table name is in column of first table. Is it possible to join or is there is an MySQL-从表中选择两列匹配的行。 如果不存在,则选择具有一列的行 - MySQL - Selecting row with two columns match from a table. If doesn't exist select row with one column 从一个表中进行选择,而在另一个表中有两个条件不成立。 可能? - SELECT from one table while two conditions are NOT TRUE in another table. Possible? 根据另一个表中的列更新表中的列。 - Update Column in a table based on column from another table. 从两个表中各选择一个记录。 通过将另一个值与新表匹配来更新一个值 - select one record each from two table. update the one value by matching the another one to a new table SQL-将一个表中多列的两行匹配到另一表中的1行。 - SQL - Matching two rows from multiple columns in one table to 1 row in another table. 另一个表中存在按列排序并删除多余的行 - order by column exist in another table and remove redundant rows 如何在表中组合两列的两个值。 - How to combine two value of two column in a table. 列表中的每个值多少次出现在另一个表的列中。 MYSQL - How many times each value from a list appears in a column in another table. MYSQL 联接两个表。 一列使用SUM - Join two table. One column using SUM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM