0
這個問題是關於這一個:Joining multiple tables to get NOT EQUAL values in MySQL更換用戶名的ID JOIN在MySQL
我想延長下面的查詢:
SELECT
d.dataid,
d.colors,
u.userid,
u.username
FROM
users u
CROSS JOIN
datas d
WHERE
(u.userid , d.dataid) NOT IN (SELECT
c.userid, c.dataid
FROM
collections c)
AND u.userid = 1
對於這個數據樣本:
table datas table users table collections
dataid | colors | addedby userid | username collectionid | userid | dataid
-------------------------- ------------------- ------------------------------
1 | blue | 1 1 | Brian 1 | 1 | 1
2 | red | 1 2 | Jason 2 | 2 | 3
3 | green | 2 3 | Marie 3 | 1 | 3
4 | yellow | 3 4 | 3 | 2
預計結果:
for Brian
dataid | colors | userid | username
-----------------------------------
2 | red | 1 | Brian
4 | yellow | 1 | Marie
for Jason
dataid | colors | userid | username
-----------------------------------
1 | blue | 2 | Brian
2 | red | 2 | Brian
4 | yellow | 2 | Marie
添加了「addedby」行,它繼承了用戶的用戶標識。 目前我的查詢替換用戶的用戶標識,而不是用用戶名從數據中添加。 我真的需要從數據庫中替換userid,而不是來自用戶的userid。 :-)
有沒有人有線索如何解決這個問題?
在此先感謝!
歡呼聲
非常混亂。但是好像你需要第二次加入'users'表。 – dnoeth