I am new bee at RDBMS, I want to get a row from one of the five tables and the name of table is value of one of the fields of another table. So I am trying to store the value in one variable from one query and then using that value query again in the table whose name is stored in a variable. I am writing queries in MySQL. I am getting errors in the syntax.
This are the query statements I am writing.
DECLARE @vcTemp VARCHAR(40)
SELECT unit_test_result.*, @vcTemp = unit_test.name
FROM unit_test_result, unit_test
WHERE unit_test_result.test_run_id = 3 && unit_test.id = unit_test_result.unit_test_id
SELECT @vcTemp.* FROM @vcTemp
But I am getting following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @vcTemp VARCHAR(40) SELECT unit_test_result.*, @vcTemp = unit_test.name ' at line 1
Can anyone help me with the syntax, please? Thanks.