Skip to content

Instantly share code, notes, and snippets.

@oojacoboo
Created September 5, 2012 05:47
Show Gist options
  • Save oojacoboo/3631211 to your computer and use it in GitHub Desktop.
Save oojacoboo/3631211 to your computer and use it in GitHub Desktop.
SET @settingName = "feeMID", @companyId = 1;
SELECT COALESCE(company_setting.value, default_setting.value) AS value
FROM default_setting
LEFT JOIN company_setting
ON company_setting.default_setting_id
WHERE default_setting.name = @settingName
AND company_setting.company_id = @companyId
@oojacoboo
Copy link
Author

SET @SettingName = "feeMID", @companyid = 1;

SELECT COALESCE(
(
SELECT cs.value
FROM default_setting ds
INNER JOIN company_setting cs
ON cs.default_setting_id
WHERE cs.company_id = @companyid
AND ds.name = @SettingName
),
(
SELECT ds.value
FROM default_setting ds
INNER JOIN company_setting cs
ON cs.default_setting_id
WHERE cs.company_id = @companyid
AND ds.name = @SettingName
)
) AS value;

@oojacoboo
Copy link
Author

SET @SettingName = "test", @companyid = 1;

SELECT COALESCE(
(
SELECT cs.value
FROM company_setting cs
LEFT JOIN default_setting ds
ON cs.default_setting_id = ds.id
WHERE cs.company_id = @companyid
AND ds.name = @SettingName
),
(
SELECT ds.value
FROM default_setting ds
WHERE ds.name = @SettingName
)
) AS value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment