如何选择与SQL中的另一个表不匹配的表行?

时间:2021-10-27 09:26:36

I am trying to display all the names from the table vocabulary where the vids do not match a vid in collapse_menu. How would I do this?

我试图显示表格词汇表中的所有名称,其中vids与collapse_menu中的vid不匹配。我该怎么做?

Table vocabulary
    vid     name
    1   Sections
    2   Posts
    6   Forums
    5   Departments
    13  Free Tags
    8   Committees
    9   Training and Workshops
    10  Policies
    12  Projects
    14  Teams

Table collapse_menu
vid
8
5
10

4 个解决方案

#1


select name from vocubulary where vid not in (select vid from collapse_menu)

从vocubulary中选择名称,其中vid不在(从collapse_menu中选择vid)

#2


I assume that you are asking for the those names in vocabulary, where the vid is not in the collapse_menu table.

我假设您要求在词汇表中使用这些名称,其中vid不在collapse_menu表中。

In which case

在这种情况下

SELECT name
FROM vocabulary
LEFT JOIN collapse_menu ON vocabulary.vid = collapse_menu.vid
WHERE collapse_menu.vid IS NULL

#3


SELECT * FROM vocabulary, collapse_menu WHERE vocabulary.vid <> collapse_menu.vid;

SELECT * FROM词汇表,collapse_menu WHERE vocabulary.vid <> collapse_menu.vid;

#4


select name 
from vocabulary as v, 
     collapse_menu as c 
where v.vid!=c.vid

Edit: Sorry, didn't read the question properly.

编辑:对不起,没有正确阅读问题。

#1


select name from vocubulary where vid not in (select vid from collapse_menu)

从vocubulary中选择名称,其中vid不在(从collapse_menu中选择vid)

#2


I assume that you are asking for the those names in vocabulary, where the vid is not in the collapse_menu table.

我假设您要求在词汇表中使用这些名称,其中vid不在collapse_menu表中。

In which case

在这种情况下

SELECT name
FROM vocabulary
LEFT JOIN collapse_menu ON vocabulary.vid = collapse_menu.vid
WHERE collapse_menu.vid IS NULL

#3


SELECT * FROM vocabulary, collapse_menu WHERE vocabulary.vid <> collapse_menu.vid;

SELECT * FROM词汇表,collapse_menu WHERE vocabulary.vid <> collapse_menu.vid;

#4


select name 
from vocabulary as v, 
     collapse_menu as c 
where v.vid!=c.vid

Edit: Sorry, didn't read the question properly.

编辑:对不起,没有正确阅读问题。