Can you define "literal" tables in SQL? Can you define "literal" tables in SQL? sql sql

Can you define "literal" tables in SQL?


I suppose you could do a subquery with several SELECTs combined with UNIONs.

SELECT a, b, c, dFROM (    SELECT 1 AS a, 2 AS b, 3 AS c, 4 AS d    UNION ALL     SELECT 5 , 6, 7, 8) AS temp;


You can do it in PostgreSQL:

=> select * from (values (1,7), (2,6), (3,13), (4,12), (5,9) ) x(id, count); id | count ----+-------  1 |     7  2 |     6  3 |    13  4 |    12  5 |     9

http://www.postgresql.org/docs/8.2/static/sql-values.html


In standard SQL (SQL 2003 - see http://savage.net.au/SQL/) you can use:

INSERT INTO SomeTable(Id, Count) VALUES (1, 7), (2, 6), (3, 13), ...

With a bit more chasing, you can also use:

SELECT * FROM TABLE(VALUES (1,7), (2, 6), (3, 13), ...) AS SomeTable(Id, Count)

Whether these work in MySQL is a separate issue - but you can always ask to get it added, or add it yourself (that's the beauty of Open Source).