MySQL Select all clients that searched for two different items or more

distinctMySQL

I have a table like this :

serial,ip,term
1,1.2.3.4,bag
2,2.3.4.5,shampoo
3,1.2.3.4,handbag
4,3.4.5.6,clothes
5,2.3.4.5,battery
6,4.5.6.7,lamp

I want to select all IPs that did search for multiple different items while excluding the term 'bag' from the selection (in this case I am looking for 2.3.4.5)

Thank you very much

Best Answer

SELECT ip 
FROM my_table
WHERE UPPER(term) NOT LIKE '%BAG%'
GROUP BY ip
HAVING COUNT(ip) > 1;

Normally I would recommend against using a function in a search (UPPER()), but since the wildcard is there, the expression is non-sargable in any case!

The db-fiddle is here!