LoginSignup
0
0

More than 1 year has passed since last update.

How to SELECT fictitious records without using FROM in SQL

Last updated at Posted at 2019-04-16

Just pass a string or a number to SELECT.

 SELECT 'john', 'programmer', 30; 

result:

 +------+-----------+----+ | 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; 

result:

 +------+------------+-----+ | 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)

environment

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

reference

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

About this translattion

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0