Is there any SQL subquery syntax that lets you define, literally, a temporary table?
For example, something like
SELECT MAX(count) AS max, COUNT(*) AS count FROM ( (1 AS id, 7 AS count), (2, 6), (3, 13), (4, 12), (5, 9) ) AS mytable INNER JOIN someothertable ON someothertable.id=mytable.id
This would save having to do two or three queries: creating temporary table, putting data in it, then using it in a join.
I am using MySQL but would be interested in other databases that could do something like that.
The PL/SQL Literals A literal is an explicit numeric, character, string, or Boolean value not represented by an identifier. For example, TRUE, 786, NULL, 'tutorialspoint' are all literals of type Boolean, number, or string. PL/SQL, literals are case-sensitive.
There are four kinds of literal values supported in SQL. They are : Character string, Bit string, Exact numeric, and Approximate numeric.
Table literals are used to pass the name of a table or a placeholder value (instead of a table name) to a query. Table literals appear in the FROM clause of a SQL statement and consist of either the table name, or a SQL variable or API bind variable in place of the table name.
The terms literal and constant value are synonymous and refer to a fixed data value. For example, 'JACK', 'BLUE ISLAND', and '101' are all character literals; 5001 is a numeric literal. Character literals are enclosed in single quotation marks so that Oracle can distinguish them from schema object names.
I suppose you could do a subquery with several SELECT
s combined with UNION
s.
SELECT a, b, c, d FROM ( SELECT 1 AS a, 2 AS b, 3 AS c, 4 AS d UNION ALL SELECT 5 , 6, 7, 8 ) AS temp;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With