0

Is there any way to assign a value, which is acquired from select clause, to a variable so that I can use that variable in other query?

For example, I want to give gold, silver, and bronze medal to first, second, and third place holder respectively.

I have a table(mytable) with records (second), and I will get the name of the top three by

select name from mytable order by second desc limit 3;

and somehow I would like to assign $goldwinner=name1, $silverwinner=name2, $bronzewinner=name3

so that I can use it for

update medaltable set gold = gold + 1 where name = $goldwinner

and same for silver and bronze..

Is there any way I can do this??

Sardonic
  • 441
  • 3
  • 8
  • 19
  • There's always a way. In your case, you don't need variables. [Refer to this question](http://stackoverflow.com/questions/8057565/mysql-update-statement-inner-join-tables) to see what the guys did to have it done in a single query. – N.B. Aug 14 '15 at 14:39
  • You wouldn't normally store data that can be easily derived from other data – Strawberry Aug 14 '15 at 14:51

0 Answers0