DISTINCT 在 sqlite 查询 android 中不起作用

问题描述 投票:0回答:1
 """select distinct "data" from (select * from "DemoName" inner join "patient" on "DemoName"."rowid" = "patient"."rowid" where "patient"."name" LIKE '%$pattern%' and length('$pattern') <= length("patient"."name") and "patient"."archived" = 'false'
                 union
                select * from "DemoName" inner join "patient" on "DemoName"."rowid" = "patient"."rowid" where "DemoName"."word" match '$pattern*' and "patient"."archived" = 'false' and score < 800 and top = 30
                ) ORDER BY CASE  WHEN name LIKE '$pattern%' THEN 0 WHEN name LIKE '%$pattern%' THEN 1 ELSE score END LIMIT 80""".trimIndent()
   

这是我用于搜索不同的查询。但由于联合运算符,我在此查询中得到了重复的值

android sql sqlite android-sqlite
1个回答
0
投票

您应该使用“UNION DISTINCT”而不仅仅是“UNION”。希望这会起作用:)

© www.soinside.com 2019 - 2024. All rights reserved.