0
Have the consultation:
SELECT *
FROM cliente,
categoria_cliente,
categoria
WHERE categoria_cliente_cliente_id = cliente_id
and categoria_id = categoria_cliente_categoria_id
and (categoria_cliente_categoria_id = 1 OR categoria_cliente_categoria_id = 2)
GROUP BY cliente_id
If I do it with the OR
in the WHERE
, works perfectly, but if I change the OR
for AND
no record comes.
What I need in question is this:
Bring customers who are on the table categoria_cliente
, in this table, has the column categoria_cliente_cliente_id
and categoria_cliente_categoria_id
, with the OR
I am bringing customers who are in category 1 or 2, but with the AND
i want to bring only customers who are with category 1 and 2.
Good thing, because if the
categoria_cliente_categoria_id
for 1 and for 2 at the same time (AND) we have a problem in the universe.– Bacco
Now, if you can explain a little bit better about the type of field, if it’s numerical, if it has text, etc., we can try to help in a more objective way, of course. For example, if category is text, separated with commas, it can no longer be with =. But for this, it would be good if you [Edit] the question giving more details. Mysql has FIND_IN_SET if it is for multiple values. Example:
FIND_IN_SET( 1, categoria_cliente_categoria_id) AND FIND_IN_SET( 2, categoria_cliente_categoria_id)
– Bacco
I assume that 1 customer may per more than one category, that is, you have entries in
categoria_cliente
with the samecategoria_cliente_cliente_id
, however differentcategoria_cliente_categoria_id
correct? In that case you would like the query to return only customers associated with both categories, that’s it?– Anthony Accioly