gpt4 book ai didi

sql - 确认一下,这是一种反加入吗?

转载 作者:行者123 更新时间:2023-12-04 23:43:25 25 4
gpt4 key购买 nike

我们知道反连接是一种连接,我们试图在其中获取不匹配的行。我面临以下问题:

Find the titles of all movies that have no ratings.

我开发了以下 SQL 查询来满足这一点:

select Movie.title
from Movie
where Movie.mID not in (select Rating.mID from Rating)

我之前遇到过反加入这个词,我只是想确认一下这确实是一个反加入。特别是这是一个正确的反加入。

最佳答案

你可以查看这个article :

This is very slow and inefficient, because the RDBMS has to compare each row with an entire table of values. The following is much much faster, as it matches up each row once, then simply eliminates the results that are not in the second table:

SELECT
*
FROM table1 t1
LEFT JOIN table2 t2 ON t1.id = t2.id
WHERE t2.id IS NULL

关于sql - 确认一下,这是一种反加入吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35797478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com