How to add condition on multiple-join table
Posted
by Jean-Philippe
on Stack Overflow
See other posts from Stack Overflow
or by Jean-Philippe
Published on 2010-03-15T20:12:20Z
Indexed on
2010/03/15
20:19 UTC
Read the original article
Hit count: 242
Hi, I have those two tables:
client:
id (int) #PK
name (varchar)
client_category:
id (int) #PK
client_id (int)
category (int)
Let's say I have those datas:
client: {(1, "JP"), (2, "Simon")}
client_category: {(1, 1, 1), (2, 1, 2), (3, 1, 3), (4,2,2)}
tl;dr client #1 has category 1, 2, 3 and client #2 has only category 2
I am trying to build a query that would allow me to search multiple categories. For example, I would like to search every clients that has at least category 1 and 2 (would return client #1). How can I achieve that?
Thanks!
© Stack Overflow or respective owner