replacing several nested queries and UNION ALL with a single query

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

replacing several nested queries and UNION ALL with a single query

Puneet Kishor-2
(this could be a potentially duplicate post -- I was sure I sent it out, but I can't find it in the out box. So, here goes again)

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

My current query is very cumbersome. I am doing one query, then UNIONing it with the results of second query from the complement of the first query then UNIONing that with with results of the third query from the complement of the first and the second query and so on.


--
Puneet Kishor
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users