On Feb 24, 2009, at 2:15 PM, John Elrick wrote:

> I may be overlooking something obvious, however, I cannot discern from
> the documentation if this is possible.
>
> given a simple example:
>
> create table x (x_id integer);
> create table y (y_id integer, y_value varchar);
>
> insert into x values (1);
> insert into x values (2);
> insert into y values (1, 'Hello world');
>
> select case when
>  (select y_value from y where y_id = x_id)
> is null then
>  'darn'
> else
>  (select y_value from y where y_id = x_id)
> end
> from x
>
>
> Is there any way to eliminate the second (select y_value from y where
> y_id = x_id)?   If so, what would the query look like?
>

SELECT coalesce((SELECT y_value FROM y WHERE y_id=x_id), 'darn') FROM x;

>
> John Elrick
> Fenestra Technologies
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

D. Richard Hipp
d...@hwaci.com



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

Reply via email to