---
title: "Mysql: Sub-query update on same table?"  
description: "Mysql: Sub-query update on same table?"  
author: "Anonymous User"  
published: 2013-07-09  
updated: 2013-07-09  
canonical: https://www.mindstick.com/forum/1273/mysql-sub-query-update-on-same-table  
category: "mysql"  
tags: ["mysql"]  
reading_time: 1 minute  

---

# Mysql: Sub-query update on same table?

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
I can see why this is problematic, but can't seem to work out the fix like [others](https://answers.mindstick.com/qa/33516/what-is-dependency-injection-do-you-use-any-di-library-in-your-project-can-you-name-a-few-of-them-and-why-one-is-better-than-others) here on SO have..\
I wan't to [increment](https://www.mindstick.com/forum/173/auto-increment-id) the ticket number using a sub_query. Can't use auto_inc as [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) have an auto_inc'ing [primary key](https://www.mindstick.com/blog/214/primary-key)..\
Here's what i want to do:\
**[UPDATE](https://www.mindstick.com/forum/156353/what-is-hummingbird-update) tickets SET tickets.ticket_number=(** **[SELECT](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) (MAX(ticket_number)+1) FROM tickets****) WHERE ticket_id=12345;****\**Gives me: You can't specify [target](https://yourviews.mindstick.com/view/81207/small-industries-should-be-the-target-of-economic-relief-package) table 'tickets' for update in FROM [clause](https://www.mindstick.com/forum/33937/difference-between-throw-exception-and-throw-clause)\
Thanks!

## Replies

### Reply by AVADHESH PATEL

Hi Ida!\
Correct me if I'm wrong, but is it a result you wanted to achieve?:\
**UPDATE tickets SET tickets.ticket_number=(** **SELECT max_ticket FROM (** **SELECT (MAX(ticket_number)+1) AS max_ticket FROM tickets ) AS sub_table)** **WHERE ticket_id=12345;**


---

Original Source: https://www.mindstick.com/forum/1273/mysql-sub-query-update-on-same-table

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
