Select default setting for user from default table if user setting table is empty
<p>my sql is weak and I'm struggling to get the results I want and am sure it's something simple.</p>

<p>I have three tables:</p>

<pre><code>user, usersetting and defaultsetting
</code></pre>

<p>User table columns:</p>

<pre><code>UserId | Email
</code></pre>

<p>UserSetting table columns:</p>

<pre><code>UserId | SettingKey | IsEnabled
</code></pre>

<p>DefaultSetting table columns:</p>

<pre><code>SettingKey | IsEnabled
</code></pre>

<p>A user will only have a record in the usersetting table if they have updated their setting explicitly otherwise they should just get the setting from the defaultSetting table. Settings are either on or off for a user (IsEnabled)</p>

<p>I want to write a query that gets all the users that have setting X (settingKey = x) enabled. If a user does not have a row for setting x in their UserSettings table but the default setting IsEnabled = true then I still want to get a row for that user.</p>

<p>so logically I want to do this</p>

<pre><code>Select UserId, Email from User if they have turned setting x on explicitly or setting x defaults to on
</code></pre>