SQL-选择-外键

SQL-选择-外键,sql,select,left-join,Sql,Select,Left Join,我需要选择表VISITSEXIT,当她带来VISITSENTRY时,也会带来idvisitor和idvisitor(visitor)的描述。简单的直截了当会给你想要的: VISITSEXIT VISITSENTRY VISITOR idvisitsexit idvisitsentry idvisitor idvisitsentry idvisitante

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

简单的直截了当会给你想要的:

VISITSEXIT              VISITSENTRY               VISITOR
idvisitsexit            idvisitsentry             idvisitor 
idvisitsentry           idvisitante               visitor 
idvisitor               visitor
visitor
dateexit
timeexit
如果要包含其他表中那些不匹配的行,可能还需要使用
左JOIN
。有关
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;