2 回答

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊
您可以使用 NOT IN
SELECT `driverName`
FROM `A Drivers`
WHERE `driverYear` = 2020
AND `driverName` NOT IN (SELECT `driverA`
FROM `user_picks`
WHERE `userID` = 1
AND `raceYear` = 2020)

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊
我知道您希望兩個(gè)表中的驅(qū)動(dòng)程序名稱不重復(fù)。如果是這樣,您可以使用union:
SELECT `driverName` FROM `A Drivers` WHERE `driverYear` = 2020
UNION
SELECT `driverA` FROM `user_picks` WHERE `userID` = 1 AND `raceYear` = 2020
這將為您提供一個(gè)結(jié)果集,其中只有一個(gè)名為 的列driverName,沒有重復(fù)項(xiàng)。
另一方面,如果您想要第一個(gè)查詢中的記錄在第二個(gè)查詢的結(jié)果中不存在,則可以使用not exists:
SELECT `driverName`
FROM `A Drivers` ad
WHERE
`driverYear` = 2020
AND NOT EXISTS (
SELECT 1
FROM `user_picks` up
WHERE up.`userID` = 1 AND `up.raceYear` = 2020 and ip.`driverA` = ad.`driverName`
)
- 2 回答
- 0 關(guān)注
- 135 瀏覽
添加回答
舉報(bào)