I have a Supertype/Subtype relationship for Products, Frames and Liquids, and now I want determine what subtype it is by having the supertype product_id. I'm using:
SELECT p.*
, a.*
, l.*
FROM products p
LEFT
JOIN frames a
ON p.product_id = a.frame_id
LEFT
JOIN liquids l
ON p.product_id = l.liquid_id
WHERE p.product_id = 3
The product_id cannot be shared between the subtypes, so only one join gets data. That means I get a lot of fields that have nothing to do with the product that was found, and I dislike that a lot, to the point of being sure that there "must be another, better way".
Thank you.
question from:
https://stackoverflow.com/questions/66069036/find-the-subtype-by-having-the-supertype-primary-key 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…