I have 3 tables and each one with different structure and number of different columns, but the first 4 columns are the same in all tables. For instance
Table 1
- Type
- id1
- id2
- Period
- FirstName
- LastName
- Value
table2
- Type
- id1
- id2
- Period
- Hours
- Days
table3
- Type
- id1
- id2
- Period
- Sex
- Address
I currently run a stored procedure
@Numeric period (6,0)
begin
select * from table1 where @ Period = 202109;
select * from table2 where @ Period = 202109;
select * from table3 where @ Period = 202109
end
... and I get the following results:
Type | id1 | id2 | Period | FirstName | LastName | Value
Type | id1 | id2 | Period | FirstName | LastName | Value
Type | id1 | id2 | Period | FirstName | LastName | Value
Type | id1 | id2 | Period | Hours | Days
Type | id1 | id2 | Period | Hours | Days
Type | id1 | id2 | Period | Hours | Days
Type | id1 | id2 | Period | Sex | Address
Type | id1 | id2 | Period | Sex | Address
Type | id1 | id2 | Period | Sex | Address
but what I need is the result to be like this:
Type | id1 | id2 | Period | FirstName | LastName | Value
Type | id1 | id2 | Period | Hours | Days
Type | id1 | id2 | Period | Sex | Address
Type | id1 | id2 | Period | FirstName | LastName | Value
Type | id1 | id2 | Period | Hours | Days
Type | id1 | id2 | Period | Sex | Address
Type | id1 | id2 | Period | FirstName | LastName | Value
Type | id1 | id2 | Period | Hours | Days
Type | id1 | id2 | Period | Sex | Address
The fields Type
, id1
, id2
and Period
are the keys and the search criteria.
postgresql
tag as the code is clearly for SQL Server