简体   繁体   English

SQL - 包含2个特定值的所有行?

[英]SQL - All rows that contain 2 specific values?

I am currently querying a database that looks like this.. 我目前正在查询看起来像这样的数据库。

ID1 ID2 ID3 ID4 ID5 ID6 ID1 ID2 ID3 ID4 ID5 ID6

1 1个

2 2

3 3

4 4

I basically want to pull all rows where "808" AND "205" is in the ID Columns? 我基本上想拉出ID列中“ 808”和“ 205”的所有行? So rows where they are BOTH contained in the columns, it doesn't matter which columns they are in as long as they both exist on one row if that makes sense? 因此,行都包含在列中,只要有意义,只要它们都存在于一行中,都没关系?

Many thanks for any help 非常感谢您的帮助

Your table is not normalized, so I would suggest you to normalize, this will make thinks easier in the future, however I understand that sometimes we have to deal with not normalized data. 您的表未规范化,因此建议您进行规范化,这将使以后的思考变得更容易,但是我了解有时我们必须处理未规范化的数据。

Your query could look like this: 您的查询可能如下所示:

select
  *
from
  tablename
where
  '808' in (ID1,ID2,ID3,ID4,ID5,ID6)
  and
  '205' in (ID1,ID2,ID3,ID4,ID5,ID6)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM