【问题标题】:SQL - SELECT - FOREIGN KEYSQL - 选择 - 外键
【发布时间】:2013-03-21 13:24:15
【问题描述】:
VISITSEXIT              VISITSENTRY               VISITOR
idvisitsexit            idvisitsentry             idvisitor 
idvisitsentry           idvisitante               visitor 
idvisitor               visitor
visitor
dateexit
timeexit

我需要选择表格VISITSEXIT,当她带上VISITSENTRY时也会带上idvisitor和idvisitor(visitor)的描述。

【问题讨论】:

  • 到目前为止你写了什么查询,为什么它对你不起作用?

标签: sql select left-join


【解决方案1】:

一个简单直接的JOIN 会给你你想要的:

SELECT
  t.idvisitor,
  t.visitor,
  t.dateexit,
  t.timeext,
  ... -- the rest of the columns you want to select 
FROM VISITSEXIT       AS t
INNER JOIN VisitEntry AS e ON t.idvisitentry = e.visitentry
INNER JOIN Visitor    AS v ON e.idvisitante  = v.idvisitor;

如果您想包含其他表中那些不匹配的行,您可能还需要使用LEFT JOIN。有关JOIN 类型的更多信息,请参阅这篇文章:

【讨论】:

    猜你喜欢
    • 2017-11-13
    • 2016-08-18
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    相关资源
    最近更新 更多