Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL #1093 - You can't specify target table 'giveaways' for update in FROM clause

I tried:

UPDATE giveaways SET winner = '1' WHERE ID = (SELECT MAX(ID) FROM giveaways) 

But it gives:

#1093 - You can't specify target table 'giveaways' for update in FROM clause

This article seems relevant but I can't adapt it to my query. How can I get it to work?

like image 310
Eray Avatar asked Nov 30 '11 21:11

Eray


People also ask

What is MySQL used for?

MySQL is an open source relational database management system. For WordPress sites, that means it helps you store all your blog posts, users, plugin information, etc. It stores that information in separate “tables” and connects it with “keys”, which is why it's relational.

What is difference between SQL and MySQL?

SQL is a query programming language that manages RDBMS. MySQL is a relational database management system that uses SQL. SQL is primarily used to query and operate database systems. MySQL allows you to handle, store, modify and delete data and store data in an organized way.

Is MySQL DBMS or database?

MySQL is a database management system. To add, access, and process data stored in a computer database, you need a database management system such as MySQL Server.

Is SQL or MySQL better?

In terms of data security, the SQL server is much more secure than the MySQL server. In SQL, external processes (like third-party apps) cannot access or manipulate the data directly. While in MySQL, one can easily manipulate or modify the database files during run time using binaries.


1 Answers

Based on the information in the article you linked to this should work:

update giveaways set winner='1' where Id = (select Id from (select max(Id) as id from giveaways) as t) 
like image 198
ipr101 Avatar answered Sep 17 '22 17:09

ipr101