Puneet Kishor <[email protected]> wrote:
> Say I have table like so
>
> CREATE TABLE t (
> a1, a2,
> b1, b2,
> c1, c2
> );
>
> I want
>
> a1 AS foo WHERE a1 != '' AND a2 != '' AND a1 = a2
>
> from the remaining
>
> b1 AS foo WHERE b1 != '' AND b2 != '' AND b1 = b2
>
> from the remaining
>
> c1 AS foo WHERE c1 != '' AND c2 != '' AND c1 = c2
>
> from the remaining
>
> 'none' AS foo
>
> Right now I am doing a bunch of UNION ALLs of separate queries, but am
> wondering if there is a better way.
select (case
when a1 != '' AND a2 != '' AND a1 = a2 then a1
when b1 != '' AND b2 != '' AND b1 = b2 then b1
when c1 != '' AND c2 != '' AND c1 = c2 then c1
else 'none' end) as foo
from t;
--
Igor Tandetnik
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users