在标准SQL中是否定义了"Where IN"(具有多个列)? [英] Is “Where IN” with multiple columns defined in Standard SQL?

查看:154
本文介绍了在标准SQL中是否定义了"Where IN"(具有多个列)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理这样的查询:

I'm working on a query like this:

SELECT * FROM requests where (id,langid) IN (SELECT nid,langid FROM node)

我的问题是

  • 在mysql和postgresql中可以工作吗?
  • 这是标准SQL支持的吗?

    My questions are

  • does this work in mysql and postgresql ?
  • is this something supported by Standard SQL ?

    我知道这不是最好的解决方案,JOIN可以解决问题,但我对此并不感兴趣.

    I know is not the best solution and a JOIN would work but I'm not interested in that.

    推荐答案

    标准和可移植的SQL将是EXISTS ..,并且在语义上是相同的IN

    Standard and portable SQL would be EXISTS.. and is semantically the same IN

    SELECT *
    FROM requests R
    WHERE 
        EXISTS (SELECT *
               FROM node n
               WHERE r.id = n.nid AND r.langid = n.langid
               )
    

    多列IN至少不能移植到SQL Server或Sybase.

    The multi-column IN isn't portable to SQL Server or Sybase at least.

    其他说明:

    • JOIN可能需要DISTINCT,并且与IN或EXISTS不同.
    • 最后一个选项是"INTERSECT",它不那么受支持,并且像IN/EXISTS一样工作
    • IIRC的一些史前MySQL版本(3.x?)不支持EXISTS的关联

    这篇关于在标准SQL中是否定义了"Where IN"(具有多个列)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆