Hi gurus, I'm basically trying to have global settings that can be overriden per object (let's say a forum as in the DDL below) ... let me explain, let's say I want to have 5 settings for all my forums, e.g. threads per page .. etc, I want those to work as global or default settings but at the same time I still want to be able to override some or all of the settings per forum.
The global (or default) settings are in the ForumSettingDefaults table, the overriden settings are in the ForumSettings table, how can we select the settings for all forums so that the resultset contains:
ForumID, SettingName, SettingValue (if the setting is overriden, ie. exists in the ForumSettings table, the value is taken from there otherwise we get the value from the ForumSettingDefaults table).
Here's the DDL for the tables and an example for the data follows:
Never mind guys, I already solved the problem, here's the select statement:
CONCAT(Forums.ForumID, ForumSettingDefaults.SettingName) NOT IN (SELECT CONCAT(ForumID, SettingName) FROM ForumSettings)
If you have any better solution, it would be very nice to post it here.
, COALESCE(s.SettingValue,d.SettingValue) AS SettingValue
FROM Forums AS f
JOIN ForumSettingDefaults AS d
JOIN ForumSettings AS s
ON s.ForumID = f.ForumID
AND s.SettingName = d.SettingName