I stumbled over a database design in which a table has in one column the name of the table that needs to be joined and in another column the foreign key to that table (integer, not the foreign key name).

I wonder how would you solve this?

This is the current situation:

*Table chatting:*

```
id   |   someColumn   |   chatter_id   |   chatter_ref
--------------------------------------------------------
1        2                1                customers
2        3                1                colleagues
3        4                2                customers

```

*Table customers:*

```
id   |   colA
-------------
1        whatever
2        hello_world

```

*Table colleagues:*

```
id   |   colB
-------------
1        yesyes

```

EDIT: 

What I'd do, would be to have multiple `chatting` tables, one for each referenced table.

Like this:

*Table chatting\_customers (with a foreign key to customers table):*

```
id   |   someColumn   |   chatter_id
------------------------------------
1        2                1         
3        4                2         

```

*Table chatting\_colleagues (with a foreign key to colleagues table):*

```
id   |   someColumn   |   chatter_id 
------------------------------------
2        3                1         

```

Instead of joining all tables and deciding from which table to select based on the column chatter\_ref (with a `select case when chatter_ref = 'customers' then customers.colA else colleagues.colB end from ...`) I would `union` multiple queries. Is this the way to go? Is there a better way to **normalize** this?