Sybase 外连接行为

发布于 2024-11-03 08:01:24 字数 790 浏览 2 评论 0原文

我正在研究一些旧版 SQL(用 sybase 术语编写)并将其转换为 SQL-92 兼容形式。问题是,我无法理解“*=”的行为方式。

查询(适当审查):

SELECT 
    C.*, SUM(P.qty) from Cars C, Parts P
WHERE 
    C.carid = 1
AND C.carid *= P.carid
AND C.missingpart *= P.missingpart
AND C.manufacturer *= P.manufacturer
AND P.qty is not null
GROUP BY C.carid, C.missingpart, C.manufacturer

我将其转换为:

SELECT
    C.*, SUM(P.qty) from Cars C
        LEFT JOIN Parts P
        ON C.carid = P.carid
        AND C.missingpart = P.missingpart
        AND C.manufacturer = P.manufacturer
WHERE
    C.carid = 1
AND P.qty is not null
GROUP BY C.carid, C.missingpart, C.manufacturer

但事实证明 - 它们并不等效。有人可以帮助我理解 sybase 外连接中“*=”的确切行为是什么以及为什么我的两个查询不相同?

谢谢:)

PS:我正在使用 Sybase ASE TDS 5.5

I'm working on some legacy SQL (written in sybase lingo) and converting it to SQL-92 compatible form. The problem is, I'm unable to understand how "*=" behaves.

the query (appropriately censored):

SELECT 
    C.*, SUM(P.qty) from Cars C, Parts P
WHERE 
    C.carid = 1
AND C.carid *= P.carid
AND C.missingpart *= P.missingpart
AND C.manufacturer *= P.manufacturer
AND P.qty is not null
GROUP BY C.carid, C.missingpart, C.manufacturer

I converted it to:

SELECT
    C.*, SUM(P.qty) from Cars C
        LEFT JOIN Parts P
        ON C.carid = P.carid
        AND C.missingpart = P.missingpart
        AND C.manufacturer = P.manufacturer
WHERE
    C.carid = 1
AND P.qty is not null
GROUP BY C.carid, C.missingpart, C.manufacturer

But turns out - they are not equivalent. Can someone help me understand what is the exact behaviour of "*=" in sybase outer joins and why my two queries are not identical?

Thanks :)

PS: I'm using Sybase ASE TDS 5.5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

穿透光 2024-11-10 08:01:24

尝试将 AND P.qty is not null 从 WHERE 子句移至连接表达式。

Try moving AND P.qty is not null from the WHERE clause to the join expression.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文