On this page

VALUES

Updated on 2022-11-18 GMT+08:00

Syntax

VALUES row [, ...]

where row is a single expression or

( column_expression [, ...] )

Description

VALUES is used to query any place that can be used (for example, the FROM clause of SELECT and INSERT). VALUES is used to create an anonymous table without column names, but tables and columns can be named using AS clauses with column aliases.

Example

  • To return a table with one column and three rows:
    VALUES 1, 2, 3
  • To return a table with two columns and three rows:
    VALUES
    (1, 'a'),
    (2, 'b'),
    (3, 'c')
  • To return the table with the column name id and name:
    SELECT * FROM ( (1, 'a'), (2, 'b'),(3, 'c')) AS t (id, name);
  • Create a table with the column id and name:
    CREATE TABLE example AS 
     SELECT * FROM (VALUES (1, 'a'), (2, 'b'), (3, 'c')) AS t (id, name);
Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback