Welcome Guest, Not a member yet? Register   Sign In
[Solved] Complicated MySQL Query (Sets)
#3

[eluser]mddd[/eluser]
If you need all tags to be linked, you could do something like this. The requested tag id's are 123 and 456 in this example.

Code:
SELECT product.* FROM product
JOIN product_tag tag1 ON tag1.product_id = product.id AND tag1.tag_id = 123
JOIN product_tag tag2 ON tag2.product_id = product.id AND tag2.tag_id = 456

So, you join the product able against the product_tag table several times. Each time on the condition that the tag matches.
This is easy to write in Active Record in CI, no matter how many tags were selected.


Messages In This Thread
[Solved] Complicated MySQL Query (Sets) - by El Forum - 08-17-2010, 03:46 AM
[Solved] Complicated MySQL Query (Sets) - by El Forum - 08-17-2010, 05:47 AM
[Solved] Complicated MySQL Query (Sets) - by El Forum - 08-17-2010, 06:57 AM
[Solved] Complicated MySQL Query (Sets) - by El Forum - 08-17-2010, 04:05 PM
[Solved] Complicated MySQL Query (Sets) - by El Forum - 08-18-2010, 03:22 AM
[Solved] Complicated MySQL Query (Sets) - by El Forum - 08-18-2010, 05:41 AM
[Solved] Complicated MySQL Query (Sets) - by El Forum - 08-18-2010, 05:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB