P
P
Peter2018-05-18 16:41:45
PostgreSQL
Peter, 2018-05-18 16:41:45

How to merge two tables with date filtering?

There are two tables in Postgresql:
TableOne
name | timestamp
---------------+-----------
a_one | 2013-07-21
---------------+-----------
b_one | 2018-05-05
TableTwo
name | timestamp
---------------+-----------
a_two | 2015-11-01
---------------+-----------
b_two | 2018-05-15
From these two tables, you need to create a virtual table with the following structure
name | timestamp
---------------+-----------
a_one | 2013-07-21
---------------+-----------
a_two | 2015-11-01
---------------+-----------
b_one | 2018-05-05
---------------+-----------
b_two | 2018-05-15
How to make the right request?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Belyaev, 2018-05-18
@volkov_p_v

SELECT "name", "timestamp" FROM (
  SELECT "name", "timestamp" FROM TableOne
  UNION ALL
  SELECT "name", "timestamp" FROM TableTwo
)
WHERE "timestamp" > '2015-01-01'::timestamp

M
Melkij, 2018-05-18
@melkij

Ordinary union all.

select ... from a ...
union all
select ... from b ...

You can make a view.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question