我有两张桌子:
+--------------+ +------------------+
| files | | locked |
|--------------| |------------------|
| filename | | user | filename|
+--------------+ +------------------+
| /f1/f2/xy.txt| | 77 | /f1 |
| /f3/xx/xx.doc| | 65 | /abc |
| /x.txt | | 77 | /f3/xx |
+--------------+ +------------------+
(The're a lot more files and locked filenames, but so its easier to understand)
表files
包含我所有文件的列表。表locked
包含一个包含文件夹的列表。
例如,在第一行中定义user 77
不允许files
看到以f1
开头的SELECT filename FROM files f
LEFT JOIN locked l ON f.filename LIKE CONCAT(l.filename,'%')
WHERE user='77';
。
所以我的愿望是这样的声明:
NOT IN(SELECT...)
我无法使用{{1}}执行此操作,因为它会变慢。
答案 0 :(得分:1)
http://sqlfiddle.com/#!2/12f23/5/0
SELECT f.filename FROM files f
LEFT JOIN locked l ON user=77 AND LOCATE(l.filename, f.filename) = 1
WHERE l.filename IS NULL;
结果:
FILENAME
/x.txt