what is the best way how to solve this situation?
Let's say you have a table Property with columns
Property ID, Property Description, Property Type, Property Type Related ID....
If Property Type is Selling then Property Type Related ID is from table for selling
If Property Type is Renting then Property Type Related ID is from table for renting
SELECT
propertyID,
propertyDescription,
(CASE WHEN relatedSelling.selling ID IS NOT NULL THEN relatedCOl1
WHEN relatedRenting.selling ID IS NOT NULL THEN relatedCOl1
END) as RelCol1,
(CASE WHEN relatedSelling.selling ID IS NOT NULL THEN relatedCOl2
WHEN relatedRenting.selling ID IS NOT NULL THEN relatedCOl2
END) as RelCol2,
..... is there a way how to get this data and not having case for each column? there is about 15 columns which I need to have in a select from those related tables(or other tables joined with these related)
FROM Property
LEFT JOIN ON selling WHERE property. propertyTypeRelatedID = selling ID and property.propertyType = 'Selling' as relatedSelling
LEFT JOIN ON renting WHERE property. propertyTypeRelatedID = renting ID and property.propertyType = 'Renting' as relatedRenting