PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > How would I solve this ?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How would I solve this ?

Réponse
 
LinkBack Outils de la discussion
Vieux 09/04/2008, 22h16   #1
Floortje
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 would be gratly appreciated because I dont know how to do this :-(


Floortje
  Réponse avec citation
Vieux 10/04/2008, 01h46   #2
toby
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 .

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


  Réponse avec citation
Vieux 10/04/2008, 12h30   #3
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h03.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08126 seconds with 11 queries