开发者

Master SQL View

开发者 https://www.devze.com 2023-02-02 01:31 出处:网络
I am wanting to create a view using postgresql that essentially shows me all information in the entire database.

I am wanting to create a view using postgresql that essentially shows me all information in the entire database.

Example:

Table 1

  • pin
  • insert_time

Table 2

  • tmr
  • insert_time

Table 3

  • weight
  • insert_time

Desired Output View

The output view would be sorted by insert_time. It would just leave the columns blank that aren't used for that row ie. If it pulled from Table 1 then PIN and insert_time would be filled but tmr and weight would be left blank.

How can I go about doing this? I can create other tables if needed, but not sure how I would do this.


CREATE VIEW everything
AS
SELECT insert_time, pin, null as tmr, null as weight
FROM table_1
UNION ALL
SELECT insert_time, null as pin, tmr, null as weight
FROM table_2
UNION ALL
SELECT insert_time, pin, tmr, weight
FROM table_3;
0

精彩评论

暂无评论...
验证码 换一张
取 消