My database stores events from C++ structs of report information. All structs have common fields (id
, timestamp
) but also unique ones (application.name
, user.name
). I need data for one component from tables with different columns.
Table1:
eventId | timestamp | application.name | … |
---|---|---|---|
1 | 1224545 | ui.exe | … |
… | … | … | … |
Table2:
eventId | timestamp | user.name | … |
---|---|---|---|
1 | 2133333 | TestUser1 | … |
… | … | … | … |
I want to use CREATE VIEW
to get:
eventId | timestamp | application.name | user.name | … |
---|---|---|---|---|
1 | 1224545 | ui.exe | {null} | … |
1 | 2133333 | {null} | TestUser1 | … |
… | … | … | … | … |
How can I do this?
You could use the UNION
operator:
CREATE VIEW viewname AS
SELECT eventid, timestamp, "application.name", NULL AS 'user.name'
FROM table1
UNION ALL
SELECT eventid, timestamp, NULL AS 'application.name', "user.name"
FROM table2