Re: union replacing values
From: Steve Kass (skass_at_drew.edu)
Date: 02/26/05
- Next message: Adam Machanic: "Re: PK Index name"
- Previous message: Bob Barrows [MVP]: "Re: THANKS! -> Re: Valid MS Access SQL Syntax (Double JOINtedness)"
- In reply to: Henri: "union replacing values"
- Next in thread: Henri: "Re: union replacing values"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 26 Feb 2005 13:29:22 -0500
Try something like this:
select
coalesce(
(
select conf_value from tab_user_conf
where user_id = @userId
)
,
(
select conf_value from tab_org_conf
where org_id = @orgId
)
)
Steve Kass
Drew University
Henri wrote:
>Hello,
>
>I want to retrieve the preferences of a user.
>There are two table.
>The first one called tab_org_conf store key-value pairs indicating the
>default preferences of the organisation the user belongs to.
>The second one called tab_user_conf store key-value pairs indicating the
>preferences specific to the user.
>My problem is that I want that user's preferences override organisation's
>default preferences.
>For instance if there's conf_key: COLOR, conf_value: blue in tab_org_conf
>and conf_key: COLOR, conf_value: red in tab_user_conf
>I only want to get the last one as selected row and not the first one.
>I've tried UNION:
>
>SELECT
> conf_key,
> conf_value
>FROM
> tab_org_conf
>WHERE
> org_id = @orgId
>
>UNION
>
>SELECT
> conf_key,
> conf_value
>FROM
> tab_user_conf
>WHERE
> [user_id] = @userId
>
>but it returns both rows.
>How can I get tab_user_conf rows to override tab_org_conf rows when conf_key
>is the same?
>
>Thanks for your help.
>
>Henri
>
>
>
>
>
- Next message: Adam Machanic: "Re: PK Index name"
- Previous message: Bob Barrows [MVP]: "Re: THANKS! -> Re: Valid MS Access SQL Syntax (Double JOINtedness)"
- In reply to: Henri: "union replacing values"
- Next in thread: Henri: "Re: union replacing values"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|