samedi 11 juillet 2015

How do you reuse a queried table?

Let's say we perform a query that leads to "ResultsTable"

I then want to combine ResultsTable with the results of another query. BUT the other query needs to use ResultsTable in its JOIN statement. Is this possible?

I'd almost compare it to a += operation as my goal is to reduce the repeating conditions in my current statements:

SELECT
    _id
FROM
    TableA
WHERE
    name="billy", age='62', hometown='new york'

UNION

SELECT
    _id
FROM
    TableB JOIN TableA
WHERE
    name='billy', age=62, hometown='new york' -- (same as above conditions for table A)
    TableA._id=TableB._id

TLDR; Can you reuse a SELECT statement or do you need to write it out everytime

Aucun commentaire:

Enregistrer un commentaire