Q:

How to relate an Entity to another one that can (but not always) belong to

I want to store information about houses. Those houses can be independent or belong to buildings. I want to store information about those buildings as well. So, a building can contain one or more houses and a house can be contained in zero or one building.
The question is how to relate in a mysql database those two entities.
The solucion I'm considering is adding to the house table an id_building that can be null but I'm not sure this is a good idea provided that it'd be a foreign key. Thank you very much in advance! 

A:

Your idea is the correct way to implement this relationship.  It is a 0/1-->n relationship.
You capture the "0" relationship with a NULL value for building_id.  You capture the "1" relationship with a valid value for building_id.

