friction
friction

Reputation: 877

How to select from union result?

I have a MySQL script like this:

SELECT ... FROM ... WHERE ...
UNION ALL
SELECT ... FROM ... WHERE ...

now how to select again from the union result?

This doesn't work:

SELECT * FROM (
    SELECT ... FROM ... WHERE ...
    UNION ALL
    SELECT ... FROM ... WHERE ...
);

Upvotes: 4

Views: 9232

Answers (2)

Vatev
Vatev

Reputation: 7590

You need to put an alias for the inner query:

SELECT * FROM (
    SELECT ... FROM ... WHERE ...
    UNION ALL
    SELECT ... FROM ... WHERE ...
) as something;

Upvotes: 11

Miguel Prz
Miguel Prz

Reputation: 13792

I think you are asking for this:

   SELECT * FROM (
      SELECT ... FROM ... WHERE ...
      UNION ALL
      SELECT ... FROM ... WHERE ...
    )
    WHERE ...

Upvotes: 0

Related Questions