开发者

MySql filtering and grouping

开发者 https://www.devze.com 2023-01-21 21:41 出处:网络
I am having trouble filtering data out a relational table.The query is part of a join, but I am stuck on a basic part.

I am having trouble filtering data out a relational table. The query is part of a join, but I am stuck on a basic part.

I need to remove all the results with a certain id if the condition is found.

query similar to:

select * from colors where color != 'red' group by id

id  color
1   red
1   blue
1   blue
2   green
2   blue
3   green
3   orange
4    red
5    white

returns 1,2,3,5

I need it to only return 2,3,5

I am not sure what mysql com开发者_JS百科mand to use


select * from colors group by id having not group_concat(color) LIKE "%red%"

should work (not tested).

But it's weird to have many ids with same value...


SELECT DISTINCT id
FROM my_table
WHERE id NOT IN (
   SELECT id
   FROM my_table
   WHERE color = ?
)
0

精彩评论

暂无评论...
验证码 换一张
取 消