简体   繁体   English

在基于嵌套 SELECT 的 SQLite LIKE 子句中使用多个搜索条件

[英]Using multiple search criteria in SQLite LIKE clause based on a nested SELECT

I have a list of full-paths in the "SOURCE" table in SQLite and a list of specific filenames (which will obviously be part of the path) in a SPECIFICFILES table.我在 SQLite 的“SOURCE”表中有一个完整路径列表,在 SPECIFICFILES 表中有一个特定文件名列表(这显然是路径的一部分)。

I want to find the files in the SOURCE table based on their filenames.我想根据文件名在 SOURCE 表中查找文件。 I'm trying to use "LIKE" to match part of the path, but the search below returns nothing:我正在尝试使用“LIKE”来匹配路径的一部分,但下面的搜索没有返回任何内容:

select * from SOURCE WHERE FullPath like (select char(39)||'%'||"SPECIFICFILES"."Filename"||'%'||char(39) FROM SPECIFICFILES);

(Char(39) is a quote in ASCII). (Char(39) 是 ASCII 中的引号)。

This query returns nothing.此查询不返回任何内容。 Is this possible in SQLite please or do I need to use C# to fire off each query in turn?请问这在 SQLite 中是否可行,还是我需要使用 C# 依次触发每个查询?

Adding some sample data:添加一些示例数据:

Table SOURCE:
FullPath
C:\My Directory\MyFile.txt

Table SPECIFICFILES:
Filename
MyFile.txt

You can do it by joining the tables:您可以通过加入表格来做到这一点:

SELECT s.*, f.* 
FROM SOURCE s INNER JOIN SPECIFICFILES f
ON s.FullPath LIKE '%\' || f.Filename || '%';

I'm not sure why you used in your code CHAR(39) .我不确定您为什么在代码中使用CHAR(39)
Is it part of the paths?它是路径的一部分吗?
Also if the filename is at the end of FullPath , without any trailing \ , there is no need to concatenate the wildcard % at the end:此外,如果文件名位于FullPath的末尾,没有任何尾随\ ,则无需在末尾连接通配符%

SELECT s.*, f.* 
FROM SOURCE s INNER JOIN SPECIFICFILES f
ON s.FullPath LIKE '%\' || f.Filename; 

See the demo .演示

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

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