MySQL Forums
Forum List  »  PHP

Re: Problem with SQL query :(
Posted by: Rick James
Date: January 21, 2014 06:22PM

Gag. EAV! One of the worst schemas around.

Anyway, you need some self JOINs...

> ( label = 6 AND properties IN (35,5) ) AND
> ( label = 7 AND properties IN (7,8) )

AND won't work; OR will

> ( label = 6 AND properties IN (35,5) ) OR
> ( label = 7 AND properties IN (7,8) )

means something like "Phone that is WHITE OR GRAY _or_ it should have Simlock for Telering or Vodafone"

If you want "Phone that is WHITE OR GRAY _and_ it should have Simlock for Telering or Vodafone", then you need two JOINs into Properties:
SELECT ... FROM ...
JOIN Properties color ON ...
JOIN Properties slock ON ...
WHERE
color.label = 6 AND color.properties IN (35,5)
AND
slock.label = 7 AND slock.properties IN (7,8)

Getting messy? Welcome to key-value schema!
Here's my blog on the topic:
http://mysql.rjweb.org/doc.php/eav

Options: ReplyQuote


Subject
Written By
Posted
January 18, 2014 10:39PM
January 19, 2014 12:30PM
January 19, 2014 12:41PM
January 20, 2014 03:24PM
Re: Problem with SQL query :(
January 21, 2014 06:22PM
January 22, 2014 04:19PM
January 23, 2014 12:15AM
January 23, 2014 10:23AM
January 19, 2014 12:33PM


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.