I want to use SELECT
clause inside the VALUES
like this: The point is to get a random value from another table
VALUES (SELECT x FROM seq_data ORDER BY RAND() LIMIT 1;, ...)
Yet this returns an error,
Otherwise I have to set variable and the execution becomes so slow like that
SELECT @id := x FROM seq_data ORDER BY RAND() LIMIT 1;
VALUES(@id, ... )
What is the solution around this?
2
Answers
If you use a subquery in place of a scalar value, you must put it in parentheses:
Also: don’t use a semicolon (
;
) inside a subquery. Only use a semicolon at the end of the whole statement.Use
INSERT .. SELECT
: