MySQL Forums
Forum List  »  German

m:n Relation und Abfrage mit Filter (statustabelle)
Posted by: Manuel Ruetz
Date: November 30, 2009 09:58AM

Hallo,

entschuldigt die schlechte beschreibung im Topic, aber mein Problem ist etwas
schwierig zu beschreiben.

Folgende Tabellenstruktur (der Einfachheit halber etwas gekürzt):

STORAGEBIN
==================
idStorageBin
description
number

STORAGEBINSTATUS
==================
idStorageBin
description


STORAGEBINHASSTATUS
==================
idStoragebin
idStoragebinStatus


Also ein m:m-Beziehung. Ein Storagebin ist ein Behälter, der mehrere Stati
haben kann.

Die Aufgabenstellung ist nun folgende:

Alle Storagebins, die den status mit der ID 1 UND 2 UND NICHT 3 haben, sollen
selektiert werden.

Ein einfaches

SELECT s.* FROM storagebin s
LEFT JOIN storagebinhasstatus shs ON (s.idstoragebin = shs.IdStoragebin)
LEFT JOIN storagebinstatus st ON (st.idstoragebinstatus = shs.IdstoragebinStatus)
WHERE st.IdstoragebinStatus = 1 AND st.IdstoragebinStatus = 2
AND NOT st.idstoragebinstatus = 3;

liefert 0 Records, da ja idstoragebinstatus jeweils nur 1 Wert beinhaltet.

Hinzu kommt noch, dass die WHERE Bedingungen variabel sind und vom
Benutzer angegeben werden. D.h. es sind Bedingungen wie

(status = 1 OR (status = 5 AND status = 3)) AND status = 9

möglich.

Ich hoffe, daß ich mein Problem verständlich dargestellt habe.

Hat jemand eine Idee, wie man das Problem elegant lösen kann?


Gruß

Manuel

Options: ReplyQuote


Subject
Views
Written By
Posted
m:n Relation und Abfrage mit Filter (statustabelle)
3223
November 30, 2009 09:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.