0

I have a database that has different financial article tables for each article type. For example:

fa_meds_01 with the ID column name FA_MED_ID,
fa_uniforms_02 with the ID column name FA_U_ID,
fa_trips_03 with the ID column name FA_T_ID,
fa_experts_04 with the ID column name FA_E_ID.

These IDs are going to be named differently like MED1, U1, T1, etc..

I want to store all of these in to a single table called t_fin_articles with the ID column named A_ID which is going to be referenced to a general expenses journal with all the other details.

So expected result should be the table t_fin_articles showing under A_ID IDs those financial article tables.

How would one go about doing such a task? Or maybe those different tables could be referenced to the general expenses journal directed?

MariusG96
  • 87
  • 2
  • 9
  • 4
    Don't forget the question! (And take a look at [mcve] too.) – jarlh Nov 21 '19 at 09:05
  • Typically you would use inheritance for this kind of issue. It sounds like the section in [this answer](https://stackoverflow.com/a/3579462/1048425) about class inheritance would be most appropriate. In summary, you would generate unique IDs in your table `t_fin_articles`, then you would re-use these IDs in your other tables, not the other way round. – GarethD Nov 21 '19 at 09:11

1 Answers1

0

You can combine all the ids from different tables using union operation. An example would be like below:

select
    FA_MED_ID as id
  from
    fa_meds_01
union all
    select
      FA_U_ID as id
    from
      fa_uniforms_02
union all
    select
      FA_T_ID as id
    from
      fa_trips_03
union all
    select
      FA_E_ID as id
    from
      fa_experts_04

add any other required fields also to each select statement with a common column alias so that the union will work fine.

Leni
  • 653
  • 1
  • 6
  • 23