简体   繁体   English

查找表 sqlite 中不存在的所有记录

[英]Find all records which does not exist in table sqlite

ٰI am working on a dictionary application based on php and sqlite. ٰ我正在开发基于 php 和 sqlite 的字典应用程序。 I want to make an option through which user can validate list of words which does not exits in database.我想创建一个选项,用户可以通过该选项验证数据库中不存在的单词列表。 I wonder if there is anyway I can validate the list in a single query.我想知道是否无论如何我可以在单个查询中验证列表。

Edit Following is table structure编辑以下是表结构

word | definition
word 1 | definition 1
word 2 | definition 2
word 3 | definition 3

结构

Left join input list to the target table/column and keep rows having NULL in the fields from the "words" table.将输入列表左连接到目标表/列,并在“单词”表的字段中保留具有 NULL 的行。

WITH
    query_input(word) AS (
        VALUES ('word 1'), ('word 2'), ('word 0'), ('word 3'), ('word 5')
    ),
    -- Remove this CTE when querying against your db.
    dict(id, word, definition) AS (
        VALUES
            (1, 'word 1', 'definition 1'),
            (2, 'word 2', 'definition 2'),
            (3, 'word 3', 'definition 3')
    ),
    new_words AS (
        SELECT query_input.*
        FROM query_input
        LEFT JOIN dict ON query_input.word = dict.word
        WHERE dict.id IS NULL
    )
SELECT * FROM new_words;

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

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