fuchsi schrieb am 22.January.2009, 16:21:07 in der Kategorie pc.coding
mysql abfrage - verständnissproblem
> servus derms und madels, > > ich hab ein kleines problem mit dem verständniss von einer mysql abfrage. > ich habe folgende abfrage: > > > SELECT DISTINCT products_id FROM products_attributes WHERE options_id > = 10 AND options_values_id = 41 AND options_id = 8 AND options_values_id = > 36 >
da kann er auch nichts finden, denn du willst alle Datensätze wo
options_id = 10 und gleichzeitig 8 ist. Sowas sollte es nicht geben.
> > > SELECT DISTINCT p.products_id FROM products_attributes p, > products_attributes a WHERE p.options_id = 10 AND > p.options_values_id = 41 AND a.options_id = 8 AND > a.options_values_id = 36 >
Damit verknpüfst Du die Tabelle products_attributes mit sich selbst, und zwar jeden Datensatz mit jedem Datensatz !!
Dann gibts natürlich den Datensatz wo
p.options_id = 10 und a.options_id = 8 ist, da wie gesagt jeder Datensatz mit jedem Datensatz verknüpft ist.
Aber Achtung, sowas bremst jedes System gewaltig ein!!!
Ich denke du willst eher sowas.
SELECT DISTINCT products_id FROM products_attributes WHERE
(options_id = 10 AND options_values_id = 41) OR
(options_id = 8 AND options_values_id = 36