我有一张桌子,看起来像这样:
id | colors | other column | other column |
---|---|---|---|
1 | red, green, blue | ... | ... |
2 | red, blue | ... | ... |
3 | red | ... | ... |
4 | white, blue, purple | ... | ... |
5 | green, white, purple | ... | ... |
我需要一个SQL查询,它将返回值与我的过滤器列表中的值匹配only的行,而不返回在Colors列中有任何其他值的行.
我正在处理的查询如下:
select * from table where colors in ('red', 'blue');
这个函数的问题在于,它将在结果中返回第1-4行,因为每一行的 colored颜色 都是红色或蓝色.相反,我只想返回第2行和第3行,这是我的滤镜列表之外唯一没有任何额外 colored颜色 的行.
列中可能有任意数量的 colored颜色 ,所以很遗憾我没有一个很好的列表来用作NOT
滤镜.我需要能够从数据库返回整个行,包括所有可用列.
感谢任何帮助或建议.
蒂娅!