Shellsunde
Shellsunde

Reputation: 76

Syntax to select into two variables in one select statement (MySQL)

Isn't it possible to select into two variables in a single select statement? Please help me get this simple syntax. id and date_start both are columns in the table data_set. The WHERE clause restricts the results to one row. Naturally, when I do this as two selects, one for each variable, it works.

select id into @id_data_set, date_start into @start_date from data_set
where name_table = 'debug_data_1';

ERROR 1327 (42000): Undeclared variable: date_start

Upvotes: 1

Views: 650

Answers (1)

potashin
potashin

Reputation: 44601

Just correct your sql syntax : at first list all fields and after that, in the INTO clause, list all variables. For more information look here. Your query :

SELECT id
     , date_start 
INTO @id_data_set
   , @start_date
FROM data_set
WHERE name_table = 'debug_data_1';

Upvotes: 1

Related Questions