目次
とある日
MySQLで、
— atsuizo (@atsuizo) 2021年4月15日
select sleep(10);
と
select count(*) from (select sleep(10)) a;
は
sleep(10)が発動して
「1 row in set (10.01 sec)」
になるけど、
select count(*) from (select sleep(10) where 1=2) a;
は
sleep(10)が発動しなくて
1 row in set (0.00 sec)
になる。
という小ネタ。
MySQLで、 select sleep(10); と select count(*) from (select sleep(10)) a; は sleep(10)が発動して 「1 row in set (10.01 sec)」 になるけど、 select count(*) from (select sleep(10) where 1=2) a; は sleep(10)が発動しなくて 1 row in set (0.00 sec) になる。 という小ネタ。
今回調べるのは、sleepの小ネタではなくFROM句がなくてどこまでSQLを記述できるのかを調べます。
純粋にFROM句がないSQLが不自然極まりなく気になったのでくだらないことですが気になります。
MySQL
SELECT
mysql> select 1; +---+ | 1 | +---+ | 1 | +---+ 1 row in set (0.00 sec)
WHERE
mysql> select 1 where 0 = 0; +---+ | 1 | +---+ | 1 | +---+ 1 row in set (0.00 sec)
GROUP BY
mysql> select 1 where 0 = 0 group by 1; +---+ | 1 | +---+ | 1 | +---+ 1 row in set (0.00 sec)
HAVING
mysql> select 1 where 0 = 0 group by 1 having count(1) = 0; +---+ | 1 | +---+ | 1 | +---+ 1 row in set (0.00 sec)
ORDER BY
mysql> select 1 where 0 = 0 group by 1 having count(1) = 0 order by 1; +---+ | 1 | +---+ | 1 | +---+ 1 row in set (0.00 sec)
〆
FROM句なしでSQLを記述することってまったくないため気になったので調べてみた。