On 7/20/11 8:27 AM, "Simon Slavin" <slav...@bigfraud.org> wrote:

>On 20 Jul 2011, at 4:21pm, KeithB wrote:
>
>> I'd like to create a temporary table to "shadow" one of my persistent
>> tables. It will have the same columns and hold "override" values that,
>> when present, take precedence over the real values. So, I'd like to
>> search for a row by primary key, looking first in the override table,
>> and if not found, then in the real table. The result will always be
>> zero or 1 rows.
>> 
>> I can do this with two SELECTs, but that doesn't seem to be the most
>> efficient approach. I'm sure this is easy and obvious with some
>> combination of UNION, ORDER BY, and LIMIT or something, but I can't
>> figure it out.
>
>Had you considered a VIEW ?  A VIEW is a way of saving a SELECT statement
>that can be accessed as if it's a TABLE.  You could use a SELECT that
>uses a JOIN to pick a value from the appropriate TABLE.

And then, you can use coalesce() to pick up the value from the override
table, if there is one, or from the underlying table otherwise.

Will


>
>Simon.
>_______________________________________________
>sqlite-users mailing list
>sqlite-users@sqlite.org
>http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to