M Argus Chopin Gyver
M Argus Chopin Gyver

Reputation: 304

MySQL search per char

I have a table, look like this enter image description here

and I want to query the table for looking that GROUP_CONCAT(product_id SEPARATOR ', ') field have 7 and 10.

Like statement is not working well for me because it's only showing the first row and not showing the third row, even it has 7 and 10 but separated with 8 between it..

enter image description here

Is there's any WHERE STATEMENT that I can use for this ?

Upvotes: 0

Views: 37

Answers (3)

Abdan Syakuro
Abdan Syakuro

Reputation: 1054

Why should be troubled ?

Try this

SELECT * from table where field REGEXP 'abdan|copin|sher'; 

Upvotes: 1

Dave Pateral
Dave Pateral

Reputation: 1475

You can use like '7%10' for this case. But if the string sequence is 10, 8, 7, you have to include '10%7' in the query. I faced with similar case with you before, but I didn't store the data in your way.

This is a ManyToMany association, so you can store the group_contact in another table group(id int primary key, group int not null). Then use a third table middle_table(order_id int, group_id int) to map them. Hope this help for you.

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269873

You don't want a where clause, you want a having clause:

having sum(product_id = 7) > 0 and
       sum(product_id = 10) > 0

Upvotes: 0

Related Questions