I am trying to implement a database that has a table structure similar to below, where 2 tables are a subtype of a table.
An animal has a primary key, and dog and cat has a foreign key that references animal_id of animal.
animal(animal_id, bornAt)
dog(animal_id, barkSound)
cat(animal_id, meowSound)
It is worth noting that dog and cat are disjoint, so it is not possible for them to reference the same animal_id in animal.
Is there a way to use SQL code to determine the type of the animal, given the animal_id? For example, if there is a dog with animal_id of 4(not knowing the fact that animal_id 4 is dog), I would like to retrieve the data with a join from the animal and dog table.