2017-08-31 55 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") 

希望这对你的作品:)