2

How to add two different table column as reference in one field ( column ) in PostgreSQL

below my psql query:

create table salary (
  "id"  SERIAL PRIMARY KEY,
  "user_id" VARCHAR REFERENCES user_management(user_id) REFERENCES driver_management(user_id),
   "basic_pay" INT,
  "pay_group" VARCHAR,
  "pay_method" Pay_Method,
  "pay_cycle"  Pay_Cycle,
  "bank_name" VARCHAR,
  "account_number" numeric(26),
  "lmts" timestamp default current_timestamp
);

I face this Error: enter image description here

case:

  • I my case, I have 3 table, "salary", "user_management", "driver_management"
  • "user_management" and "driver_management" both table have column "user_id"
  • "user_id" in these two separate tables should use only one column "salary" > "user_id" as reference.

WHAT I AM EXPECT: enter image description here

  • Does this answer your question? [Foreign key constraints involving multiple tables](https://stackoverflow.com/questions/26065212/foreign-key-constraints-involving-multiple-tables) – Sund'er Aug 29 '22 at 05:06
  • What exactly do you want to add? Please add the _other_ table's definition and tell us what exactly you want to achieve. To me, "add two columns as reference in one field" makes no sense. Do you want to put two "separated" values into a single column? –  Aug 29 '22 at 05:25
  • @sunder sir, see the pic – Jackson Kasi Aug 29 '22 at 05:39
  • @a-horse-with-no-name help me sir – Jackson Kasi Aug 29 '22 at 05:43
  • Why the `mysql` tag? Are you looking for a DDL statement that works for Postgres _and_ MySQL? Why the `orm` tag? Are you looking for a solution in your obfuscation layer rather than a SQL script? –  Aug 29 '22 at 06:30
  • @a-horse-with-no-name "orm" & "mysql" tag maybe help me reach out this consent. because if anyone know orm, maybe also know sql query! also maybe they can face this case, like me – Jackson Kasi Aug 29 '22 at 06:34

0 Answers0