How would I solve this ?

This is a discussion on How would I solve this ? within the MySQL Database forums, part of the Database Forums category; Hi I have got a few relational tables. Simplefied it looks something like this: users (userId) items (itemId,userId,itemName) ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008
Floortje
 
Posts: n/a
Default How would I solve this ?

Hi I have got a few relational tables. Simplefied it looks something
like this:


users (userId)
items (itemId,userId,itemName)
images (imageId)
images_items (imageId,itemId)

Users can upload Images and link that image to one or more items that
the user has defined

I can easlily select all items that belong to an image (imageId = 1)
SELECT * FROM items_images WHERE imageId='1';

How would I select all the items that belong to a specific image along
with the items that the user has defined but dont belong to that image
and distinguist between those 2. Btw I know the values of itemId and userId

Your help would be gratly appreciated because I dont know how to do this :-(


Floortje
Reply With Quote
  #2 (permalink)  
Old 04-10-2008
toby
 
Posts: n/a
Default Re: How would I solve this ?

On Apr 9, 4:16 pm, Floortje <n...@none.none> wrote:
> Hi I have got a few relational tables. Simplefied it looks something
> like this:
>
> users (userId)
> items (itemId,userId,itemName)
> images (imageId)
> images_items (imageId,itemId)
>
> Users can upload Images and link that image to one or more items that
> the user has defined
>
> I can easlily select all items that belong to an image (imageId = 1)
> SELECT * FROM items_images WHERE imageId='1';
>
> How would I select all the items that belong to a specific image along
> with the items that the user has defined but dont belong to that image
> and distinguist between those 2. Btw I know the values of itemId and userId


You mean you know the itemId?

If the desired userId is U, and the desired imageId is X,

SELECT * FROM items I LEFT JOIN images_items II
ON I.itemId=II.itemId AND II.imageId=X
WHERE II.itemId IS NOT NULL OR I.userId=U

I think that should be close. Drop me a line if you need more help.

>
> Your help would be gratly appreciated because I dont know how to do this :-(
>
> Floortje


Reply With Quote
  #3 (permalink)  
Old 04-10-2008
Captain Paralytic
 
Posts: n/a
Default Re: How would I solve this ?

On 9 Apr, 21:16, Floortje <n...@none.none> wrote:
> Hi I have got a few relational tables. Simplefied it looks something
> like this:
>
> users (userId)
> items (itemId,userId,itemName)
> images (imageId)
> images_items (imageId,itemId)
>
> Users can upload Images and link that image to one or more items that
> the user has defined
>
> I can easlily select all items that belong to an image (imageId = 1)
> SELECT * FROM items_images WHERE imageId='1';
>
> How would I select all the items that belong to a specific image along
> with the items that the user has defined but dont belong to that image
> and distinguist between those 2. Btw I know the values of itemId and userId
>
> Your help would be gratly appreciated because I dont know how to do this :-(
>
> Floortje


That query would not work. There is no table called items_images
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:41 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0