dbTalk Databases Forums  

complicated SQL for MySQL

mailing.database.mysql mailing.database.mysql


Discuss complicated SQL for MySQL in the mailing.database.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rene
 
Posts: n/a

Default complicated SQL for MySQL - 07-18-2004 , 06:01 AM






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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.