samedi 11 juillet 2015

How to reuse a table with UNION?

I am trying to reuse a table in SQLite. My attempt is as follows:

SELECT
    Partials.e_sentence
FROM
        (SELECT 
            e_sentence, _id
        FROM 
            Pair 
                JOIN PairCategories
                    ON
                        _id=PairId AND CategoryId=53

        UNION

        SELECT 
            e_sentence, _id
        FROM 
            Pair
        WHERE
            e_sentence LIKE '%' || 'how often' || '%'
        GROUP BY 
            e_sentence)
    AS Parents JOIN Partials
        ON Parents._id=ParentId

UNION

SELECT
    e_sentence
FROM
    Parents

The key part I am trying to accomplish is at the bottom, where I try to UNION a table created in the previous statement. Is there a way to do this in SQLite, or am I forced to repeat the query that made the Parents table in the first half of the UNION?

Aucun commentaire:

Enregistrer un commentaire