tags:

views:

28

answers:

1

Why this query doesn’t working:

SELECT  name
FROM
    (
    SELECT  name    
    FROM    table1
    UNION
    SELECT  name
    FROM    table2
    ) q

It returns nothing, even no error or empty table.

But

SELECT  name
FROM    table1
UNION
SELECT  name
FROM    table2

Is ok. It returns table with name field full of rows from two tables.

I know that this query is redundant, but I need to make it work as part of other query.

A: 

There's nothing wrong with your query as is. Two tables, table1 and table2 with a column 'name' in each will work fine and return rows.

You said "I need to make it work as part of other [sic] query" are you testing the query you posted independently or only as part of the larger query? If it's the latter, then your problem is there, and not with what you posted.

Zurahn
even `SELECT name FROM (SELECT name FROM table1) q` does not working
Qiao
`SELECT 1 FROM (SELECT 1 FROM table1) q` does not working! With any table.
Qiao