-2

私は必要なものの正しい構文を取得するのに苦労していて、誰かが助けることができるかどうか疑問に思いましたか?

私は3つのテーブルを持っています:users、owneditems、shopitems

ユーザーからユーザーIDと都市を取得する必要があります

ownitemsからuseridとitemidを取得する必要があります

ショップアイテムからIDと都市を取得する必要があります


所有アイテムのユーザーIDとユーザーは同じになります

所有アイテムのitemidは、shopitemsのidと同じになります

ショップアイテムとユーザーの都市は同じになります


私が求めているのは、ユーザーがどの都市にいるかを調べ、その都市で所有しているアイテムを結び付けることです。

私が使ってみた構文は

SELECT users.city, users.id, shopitems.city, shopitems.id, owneditems.itemid, owneditems.userid 
FROM users, shopitems, owneditems 
WHERE users.city = shopitems.city 
  AND owneditems.itemid = shopitems.it 
  AND users.id = owneditems.userid
4

1 に答える 1

0

何をしようとしているのかは正確にはわかりませんが、LEFT JOIN代わりに を使用してみましたかINNER JOIN:

select u.city, 
    u.id, 
    s.city, 
    s.id, 
    o.itemid, 
    o.userid
from users u
left join owneditems o
    on u.id = o.userid
left join shopitems s
    on u.city = s.sity
    and o.itemid = s.itemid
于 2013-01-14T15:53:26.290 に答える