SQL - 存在,加入还是在?

时间:2014-05-26 09:28:02

标签: sql join exists

我有3张桌子。 “TERM”,“PERFORMANCE”和“COMPANY”。 TERM表引用了PERFORMANCE.ID,PERFORMANCE具有COMPANY.ID的外键。我如何只获得表演,其中包括:

terms >= now and not null
and only from specific company

╔════════════╦════╦═════════════╦════╦═════════╗
║ TERM       ║    ║ PERFORMANCE ║    ║ COMPANY ║
║ ========== ║ -> ║ =========== ║ -> ║ ======= ║
║ start_date ║    ║ price       ║    ║ name    ║
║ ...        ║    ║ ...         ║    ║ ...     ║
╚════════════╩════╩═════════════╩════╩═════════╝

2 个答案:

答案 0 :(得分:0)

SELECT *
FROM Perfomance a 
INNER JOIN Term b on a.XX = b.XX
INNER JOIN Company c on a.XX = c.XX
where
C.Name = ' '

答案 1 :(得分:0)

试试这个:

SELECT T.start_date, P.price, C.name  
FROM PERFORMANCE P JOIN
     COMPANY C ON P.COMPANY.ID=C.ID JOIN
     TERM T ON T.PERFORMANCE.ID=P.ID

尝试详细了解JOIN s。