2017-08-31 54 views
1

我有3個表:表1,表2,表3 如下圖所示:的PostgreSQL - 查詢表3

enter image description here

我將根據字段過濾所述表3。 實施例:

輸入:XXX

輸出如下所示:
輸出應根據表1的ID1。

enter image description here

我查詢中使用下面的SQL查詢:

SELECT id, 
     id1, 
     id2, 
     value 
FROM table1, 
     table2, 
     table3 
WHERE (table1.id1 = table3.id1 
     AND table2.id2 = table3.id2) 
     AND (table3.value LIKE ? 
       OR table3.value ~ '[0-9]') 

請給我這一個SQL查詢。

+0

如何你的表1,表2的樣子,因爲你運行代碼片段3個表不顯示什麼? –

+0

你現在可以看到!它顯示了所有的3個表格。 – ANK

回答

1

請找到SQL查詢:

select 
table3.id, table3.id1, table3.id2, table3.value 
from table3 
left join table1 on table3.id1=table1.id1 
where 
table1.id1 in (SELECT table3.id1 from table3 where table3.value="xxx") 

希望這對你的作品:)