简体   繁体   English

SQLite where子句在select语句中具有多个值

[英]Sqlite where clause with multiple values in select statement

I am trying a sqlite select query statement as below: 我正在尝试如下的sqlite select查询语句:

SELECT IndicatorText 
FROM Table 
where IndicatorID in('13','25','64','52','13','25','328')
      AND RubricID in('1','1','1','1','1','1','6')

This gives an output but the duplicate values are not displayed. 这样会提供输出,但不会显示重复的值。 I want to display all the values of IndicatorText even though it is duplicate. 我想显示IndicatorText的所有值,即使它是重复的。

Please help me with this query. 请帮我这个查询。

The two IN conditions are evaluated individually. 分别评估两个输入条件。

To check both values at once, you could concatenate them so that you have a single string to compare: 要一次检查两个值,可以将它们连接起来,以便只比较一个字符串:

SELECT IndicatorText
FROM MyTable
WHERE IndicatorID || ',' || RubricID IN (
        '13,1', '25,1', '64,1', '52,1', '13,1', '25,1', '328,6')

However, doing this operation on the column values prevents the query optimizer from using indexes, so this query will be slow if the table is big. 但是,对列值执行此操作会阻止查询优化器使用索引,因此如果表很大,此查询将很慢。 To allow optimizations, create a temporary table with the desired values, and join that with the original table: 要进行优化,请创建具有所需值的临时表,然后将其与原始表连接:

SELECT IndicatorText
FROM MyTable
NATURAL JOIN (SELECT 13 AS IndicatorID, 1 AS RubricID UNION ALL
              SELECT 25,                1             UNION ALL
              SELECT 64,                1             UNION ALL
              SELECT 52,                1             UNION ALL
              SELECT 13,                1             UNION ALL
              SELECT 25,                1             UNION ALL
              SELECT 328,               6)

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

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