How to SELECT fictitious records without using FROM in SQL

Just pass a string or a number to SELECT.

 SELECT 'john', 'programmer', 30; 


 +------+-----------+----+ | john | programmer | 30 | +------+-----------+----+ | john | programmer | 30 | +------+-----------+----+ 

You can use the SQL syntax for this fictional record. For example, you can AS column names with AS .

 SELECT 'john' AS Name, 'programmer' AS Job, 30 AS Age; 


 +------+------------+-----+ | Name | Job | Age | +------+------------+-----+ | john | programmer | 30 | +------+------------+-----+ 

This method is useful for checking the operation of SQL itself. (Because you do not have to create test data)


  • mysql Ver 14.14 Distrib 5.6.26, for osx 10.10 (x86_64) using EditLine wrapper


There is an RDBMS that can omit the FROM clause and an RDBMS that can not omit it. Although it can be omitted in major OSS-DBs such as PostgreSQL and MySQL and some commercial RDBMSs, it is not possible to omit the FROM clause in representative commercial RDBMSs such as Oracle and DB2.

Original by

SQL で FROM を使わず、架空のレコードを SELECT する方法


About this translattion