0

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

0
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.