complicated SQL for MySQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rene

    complicated SQL for MySQL

    Hello

    If I a user table and a item table has - in both a incremental value
    is led (ID) - and I beside it in an order table all sales the user
    lead, how I can all items to be indicated be able, which were not
    bought of usern yet?

    A beginning is:

    SELECT DISTINCT * FROM items WHERE items.itemID EMERGENCY IN (SELECT
    items.itemID FROM orders)

    And as I bring the user purely?

    Sea the following result:

    user1 buys item1 and item2
    user2 buys item3 and item1

    result of the looked for SQL inquiry

    item2 (not bought of user2)
    item3 (not bought of user1)

    The following solution brings to NULL as soon as more than one user
    existed and both different things bought, together regards it however
    everything bought (desire result quantity)

    SELECT * FROM items i LEFT JOIN orders o ON (o.itemID = i.itemID) LEFT
    JOIN users u ON (u.userID = o.userID) WHERE i.itemID IS NULL

    possibly who has any idea?

    Thanks

    Rene
Working...