简体   繁体   English

在 postgres/redshift 的多个表中使用 SELECT *

[英]Using SELECT * from multiple tables in postgres/redshift

I have 3 tables with 2 common fields for all tables (id, timestamp) .我有 3 个表,所有表都有 2 个公共字段(id, timestamp) I want to do something like this:我想做这样的事情:

SELECT * 
FROM table1, 
     table2, 
     table3 
WHERE id = '123' 
      and timestamp = '1704'

What I would expect is that it returns all the rows with the id and timestamp matching from the 3 tables.我期望的是它返回 3 个表中 id 和时间戳匹配的所有行。 How can the query be modified to achieve this?如何修改查询以实现此目的?

 select /*your_columns*/
   from table1 
   inner join table2 on table1.id = table2.id and table1.timestamp = table2.timestamp
   inner join table3 on table2.id = table3.id and table2.timestamp = table3.timestamp
 where table1.id = '123'and table1.timestamp = '1704'

See more here about JOINs在此处查看有关 JOIN的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM