这个查询是什么意思

发布于 2024-10-08 04:24:40 字数 214 浏览 0 评论 0原文

这个查询是什么意思

  select fname, lname  
  from Owner 
  where not exists 
      (select fname, lname 
            from Trainer)

我理解 :它从表所有者返回 fname 和 lname,其中这些名称不存在于表训练器中? 我说得对吗?

what does this query mean

  select fname, lname  
  from Owner 
  where not exists 
      (select fname, lname 
            from Trainer)

what i understand :it returns fname and lname from table owner where these names not exsit in table trainer ?
am i right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最偏执的依靠 2024-10-15 04:24:40

查找存在于 Owner 表中但不存在于 Trainer 表中的人员姓名。

Find the names of people who exist in the Owner table but not in the Trainer table.

娜些时光,永不杰束 2024-10-15 04:24:40

这是一种从 owner 表中获取 trainer 表中不存在的所有人列表的非常蹩脚的方法。

因此,如果 Owner 表包含

----------------
fname   | lname
----------------
clark   | kent
lois    | lane
peter   | parker

并且 Trainer 表包含

----------------
fname   | lname
----------------
peter   | parker
hal     | jordan

您应该得到一个结果集:

----------------
fname   | lname
----------------
clark   | kent
lois    | lane

Update

实际上,如果有任何记录,您的查询将不会返回任何内容在训练师表中。您可能应该使用:

select fname, lname
from Owners
where not exists (
    select fname, lname 
    from trainers 
    where fname=Owners.fname 
          and lname=Owners.lname
    )

It's a pretty lame way to get a list of everyone from the owner table that doesn't exist in the trainer table.

So, if the Owner table contains

----------------
fname   | lname
----------------
clark   | kent
lois    | lane
peter   | parker

and the Trainer table contains

----------------
fname   | lname
----------------
peter   | parker
hal     | jordan

You should get a result set:

----------------
fname   | lname
----------------
clark   | kent
lois    | lane

Update

Actually, your query won't return anything if there are any records at all in the Trainer table. You should probably be using:

select fname, lname
from Owners
where not exists (
    select fname, lname 
    from trainers 
    where fname=Owners.fname 
          and lname=Owners.lname
    )
时光磨忆 2024-10-15 04:24:40

该查询有两部分:“select”和“where”。
首先查看 where 部分:

  where not exists 
      (select fname, lname from Trainer)

如果 Trainer 表中没有任何内容,则该 where 子句的计算结果为“true”;如果其中有内容,则该 where 子句的计算结果为“false”。现在看看“选择”部分:

  select fname, lname from Owners

这会选择“所有者”表中的所有行。

综上所述:如果(且仅当)Trainer 表中没有任何内容,则查询会从 Owner 表中选择所有行,如果有,则绝对不会选择任何行。

The query has two parts: the 'select' and the 'where'.
Look at the where part first:

  where not exists 
      (select fname, lname from Trainer)

This where clause evaluates to 'true' if there is nothing in the Trainer table, and to 'false' if there is something there. Now look at the 'select' part:

  select fname, lname from Owners

This selects all rows from the 'Owners' table.

Putting this together: the query selects all rows from the Owner table IF (and only if) there is nothing in the Trainer table -- and absolutely nothing if there is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文