加入3个有条件的桌子

时间:2016-10-08 05:55:40

标签: sql

我有3个表格,例如table1table2table3以及

table1

t1_id, t1_name, t1_bookid 

表2

t2_id, t2_name, t2_t1_id, t2_bookid 

table3

t3_id, t3_name, t3_detail

如果t3_id其他t2_bookid==t3_id

,我想要抓取t1_bookid==t3_id

1 个答案:

答案 0 :(得分:0)

尝试使用以下查询。

Select t3.id
From table3 t3
Where exists (Select 1
           From table1 t1 where t1.bookId=t3.id)
   Or exists  (Select 1
          From table2 t2 where t2.bookId=t3.id)