0 votes
1 view
in SQL by (20.3k points)

Can I SELECT multiple columns into multiple variables within the same select query in MySQL?

For example:

DECLARE iId INT(20);

DECLARE dCreate DATETIME;

SELECT Id INTO iId, dateCreated INTO dCreate 

FROM products

WHERE pName=iName;

What is the correct syntax for this?

1 Answer

0 votes
by (40.3k points)

It looks like your syntax isn't quite right. You must list the fields in order before the INTO, and the corresponding target variables after like this:

SELECT Id, dateCreated

INTO iId, dCreate

FROM products

WHERE pName = iName

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...