tags:

views:

66

answers:

2
SELECT 1 FROM (SELECT 1 FROM table) q

does not working on my local server. it returns totally nothing (no error or empty table).

But SELECT 1 FROM table is ok.

What is wrong with it? is there any MySQL option for such queries?

+1  A: 

Without really being able to understand what you're wanting to achieve, the solution to this problem is:

SELECT 1 FROM (SELECT 1) q;
Andy
it is working. returns 1
Qiao
is that what you wanted?
Andy
I found it. `SELECT 1 FROM (SELECT 1 FROM table) AS q` is working. AAAASSSSS. AS on some servers matters.
Qiao
AS is optional (according to MySQL 5.0 docs at least), even though the MySQL documents suggest you use AS.
Frank Shearar
did you insert a row into (the previously empty) `table` by any chance? :)
Andy
no i spend one hour for figuring this. `SELECT 1 FROM (SELECT 1 FROM ruch) q` does not working. `SELECT 1 FROM (SELECT 1 FROM ruch) AS q` is ok.
Qiao
A: 

Assuming that you have a table called "table", the SQL's fine. In my own database:

mysql> select 1 from (select 1 from ui_towngrpcolour) foo;
+---+
| 1 |
+---+
| 1 |
| 1 |
| 1 |
+---+
3 rows in set (0.00 sec)
Frank Shearar
yes its ok. But in my local server only `AS foo` is working. Without `AS` it is not working.
Qiao