Question: I'm developing for iOS using XCode, and basically what the action my button is doing is I click the button, a sound plays for about 5 seconds, and the image of the button changes when I click it as well. So a sound plays and an Image changes at the same time. Here's the problem I'm having.

When I press the button the image changes for a second, and only stays changed if you hold your finger on it.

I have an outlet set up where I set

`button.selected= YES`

then

`button.selected= NO`

or "highlighted" in place of "selected" either way it results in one of two things. The new image that was intended to switch to on touch is now the "default" displayed, since setting it to "YES" first causes that, or it continues to do the same as above, only changing for a second.

Is there anything I can do to set the duration time of it being highlighted or selected to 5 seconds after being touched so that way it changes on touch and doesn't change back until the sound is finished?

-Extra stuff:
I'm using the Audio Toolbox framework for the sound code, and ARC is enabled.

Thanks as always!

Answer: 
Use `NOT EXISTS`:

```
SELECT up1.* 
FROM   user_preferences up1 
WHERE  ( NOT EXISTS(SELECT 1 
                    FROM   user_preferences up2 
                    WHERE  user_id = {userIdVar}) 
         AND user_id IS NULL ) 
        OR ( user_id = {userIdVar} ); 

```
There are various ways you can do this, but if all preferences have a default value, or you have a complete list of preferences somewhere else, I would do it like this:

```
select
  default_preferences.preference_name,
  coalesce(
    real_user_preferences.preference_value,
    default_preferences.preference_value) as preference_value
from
  (select * from user_preferences where user_id is null)
  as default_preferences
left join
  (select * from user_preferences where user_id = @user_id)
  as real_user_preferences
on
  real_user_preferences.preference_name = default_preferences.preference_name

```

You've tagged your question both MySQL and SQL Server, I don't know which dialect you're looking for. I know SQL Server accepts this syntax, but it might need some tweaking for MySQL.

*Edit*: funkwurm points out that subqueries make this likely to perform poorly on MySQL. If that turns out to be a problem, it can be rewritten without subqueries as

```
select
  default_preferences.preference_name,
  coalesce(
    real_user_preferences.preference_value,
    default_preferences.preference_value) as preference_value
from
  user_preferences as default_preferences
left join
  user_preferences as real_user_preferences
on
  real_user_preferences.preference_name = default_preferences.preference_name
  and real_user_preferences.user_id = @user_id
where
  default_preferences.user_id is null

```

*Edit 2*: if there are preferences that do not have a default value, the first version can be modified to use `full join` instead of `left join`, and take `preference_name` from either the defaults or the user-specific preferences, just like `preference_value`. However, the second version is not so easily modified.