How to assign multiple ID's from different tables to a single cell in SQLite?

There is a data base which includes students, teachers and other visitors. ID like to combine these three tables into a single column of the fourth table (e.g., "library card") and is it possible?
April 4th 20 at 00:41
2 answers
April 4th 20 at 00:43
Solution
I think you need to look in the direction of polymorphic relations. To begin this article will come in handy - https://habr.com/ru/post/261835/
Taxes, an interesting topic, I will now dig on this occasion) - Kolby.Waelchi47 commented on April 4th 20 at 00:46
Do you know how to make use of these polymorphic relations??? And the Internet only carbons of this article. - Kolby.Waelchi47 commented on April 4th 20 at 00:49
@Kolby.Waelchi47, you even 1 hour allocated to explore this topic, and only say Kopirka.

Polymorphic when use in nearly every project. On the example of relations (tables) phone_numbers 5e0f8eda66746688329116.png.

It stores phone numbers of all the possible organization, in particular, banks, credit organizations and pawnshops distributed across different relations.

  1. banks - banks;
  2. pawnshops - pawnshops


The selected field on the screen can be represented as a composite key (although I can criticize for this terminology).

  • model is a class (banks, pawnshops, etc.);
  • foreign_key is the primary key of the row class


In the article above is covered much better. - cathryn.Kris50 commented on April 4th 20 at 00:52
@cathryn.Kris50, so apparently I read attentively. Thank you very much) - Kolby.Waelchi47 commented on April 4th 20 at 00:55
Read the entire article and understand what you mean. Sorry, I incorrectly asked a question. Is there an example of sql code which implements a polymorphic relationship??? - Kolby.Waelchi47 commented on April 4th 20 at 00:58
April 4th 20 at 00:45
Solution
SELECT 'student', ID FROM Students
UNION
SELECT 'teacher', ID FROM Teacher
UNION
...


Or, closer to the physical model, use a single table Person ( Code, Type, Name ... ), then Citationstyle ( Code, Madperson, Room ... ).
Thank you very much - Kolby.Waelchi47 commented on April 4th 20 at 00:48

Find more questions by tags SQLSQLite