ローカル変数への SELECT クエリの結果に基づいて、テーブルにデータを挿入する SQL クエリを作成する必要があります。私の DB プラットフォームは MySQL 5.1 ですが、ここで違いが生じるとは思いません。基本的に、私がやりたいことは次のとおりです。
SELECT id INTO var_name FROM table1 WHERE some_column='something' LIMIT 1;
INSERT INTO table2 (`number`) VALUES (@var_name);
I can't get past the first statement, though, as I get the error "Undeclared variable var_name". I've also tried putting the statement in a BEGIN/END block, and a stored procedure, but then I encounter other errors which state only that there is an error on the SELECT line. What am I doing wrong?