This is what i am doing
update t1 set x=a,y=b where a and b are obtained from (select query here)
- I know the select query
- The select query returns multiple results which are the same
- When I use group by or distinct query execution slows down considerably
- a and b are forward references so mysql reports an error
- I want to set a equal to the value obtained in the first row and b equal to the value obtained in the first row for the respective columns, to avoid group by. I don’t know how to refer to the first result from the select query.
How can i achieve all this?
LIMITspecifies the number of rows to return from the beginning of the result set:SELECT * FROM t2 LIMIT 1;# Retrieve 1st rowLIMITin your case is applied in the subquery in yourfromclause.These linsk can help you out with
updatethat uses a subquery:Update with Subquery
Subqueries in MySQL, Part 1