【问题标题】:Mysql2: Getting Error : Operand should contain 1 column(s)Mysql2:出现错误:操作数应包含 1 列
【发布时间】:2015-09-10 16:27:34
【问题描述】:

我正在尝试创建以下子查询,但出现错误 - 操作数应包含 1 列。

select study_aid_id from study_aids_readers where study_aid_id 
in
 (
select s.id, s.title , p.name , s.type 
from study_aids s, profiles p 
where s.author_id = p.user_id and p.country_id = '30' and date(s.created_at) >= '2015-01-01' )

我正在尝试从 study_aids_readers 表中获取 id 列表,这些 id 存在于 study_aids 表中,然后将这些 id 与那些从配置文件表中创建学习辅助工具的配置文件进行比较。 请帮助我或向我询问更多信息以防万一。

【问题讨论】:

    标签: mysql join subquery operands


    【解决方案1】:

    MySQL 中in 的列表只能有一列。

    大概,你想要这样的东西:

    select study_aid_id
    from study_aids_readers
    where study_aid_id in (select s.id
                           from study_aids s join
                                profiles p 
                                on s.author_id = p.user_id 
                           where p.country_id = '30' and date(s.created_at) >= '2015-01-01'
                          );
    

    还要注意使用正确的显式join 语法。

    【讨论】:

      猜你喜欢
      • 2014-11-07
      • 2013-10-04
      • 1970-01-01
      • 1970-01-01
      • 2013-03-27
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多