I have three tables which have a common field which is NOT its identifier. For example:
dairy_warehouse
-dairyId (primary key)
-expiration_date
-other dairy related fields
frozen_food_warehouse
-frozenFoodId (primary key)
-expiration_date
-other frozen food related fields (not same as dairy related fields)
dry_goods_warehouse
-dryGoodsId (primary key)
-expiration_date
-other dry goods related fields (not same as frozen food or dairy fields)
I’m trying to build a report that lists all items which are expiring in the next month. I don’t think a join would work since there is no foreign key relationship between the three tables. I’m currently leaning towards adding an index on expiration_date and using a union and 3 sub-selects, but I’m concerned that this will have terrible performance. Is there a better solution?
Using a Union will not affect performance as long as each query is hitting an index. Your suggestion to add an index on
expiration_dateis the correct thing to do.There is no foreign key because I would say none of the records are related between tables.