title: POSTGRESQL Foreign Key Referencing Primary Keys of two Different Tables
body: <p>I have two tables Books and Audiobooks, both of which have ISBN as their primary keys. I have a table writtenby that has an <code>isbn</code> attribute that has a foreign key constraint to Books and Audiobooks ISBN.</p>
  <p>The issue that comes up when I insert into <code>writtenby</code> is that postgresql wants the ISBN I insert into <code>writtenby</code> to be in both Books and Audiobooks.</p>
  <p>It makes sense to me to have a table <code>writtenby</code> that stores authors and the books/audiobooks they have written, however this does not translate to a table in postgresql.</p>
  <p>The alternative solution I am thinking of implementing was having two new relations <code>audiobook_writtenby</code> and <code>books_writtenby</code> but I am not sure that is a good alternative.</p>
  <p>Could you give me an idea of how I would implement my original idea of having a single table <code>writtenby</code> referencing two different tables or how I could better design my database? Let me know if you need more information.</p>