Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table name specified twice both as a target for update and separate source for data

Tags:

sql

mysql

Update table 
Set class = 0 
Where TOTAL_HOURS = (SELECT min (TOTAL_HOURS) from tutions);

Produced Error:

Table name specified twice both as a target for update and separate source for data.

How can I fix this?

like image 723
Rudra Upadhyay Avatar asked Apr 02 '17 17:04

Rudra Upadhyay


1 Answers

I am guessing you are trying to update tutions with tutions.

Make a nested subquery so that MySQL materializes it and is no longer the same table.

Try this:

Update tutions
Set class = 0 
Where TOTAL_HOURS = (select * from (SELECT min (TOTAL_HOURS) from tutions) t);
like image 86
Gurwinder Singh Avatar answered Sep 28 '22 08:09

Gurwinder Singh