updated where statmenet for foreign keys