SQL更新并在单个查询中选择 [英] SQL Update And Select In A Single Query
本文介绍了SQL更新并在单个查询中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SQL(MySQL)中是否有一种增加值的方法,并且还可以在单个查询中返回该值.我试图避免做如下两个查询:
Is there a way in SQL (MySQL) to increment a value, and also return the value in a single query. I am trying to ovoid doing two queries like the following:
查询1
UPDATE my_table SET my_col = (my_col + 1) WHERE something = something_else;
查询2
SELECT my_col FROM my_table WHERE something = something_else;
谢谢.
推荐答案
To my knowledge there is still no such possibility in MySQL, but take a look at this question for a possible workaround that at least lets you have the select and update work with the same data transactionally.
这篇关于SQL更新并在单个查询中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文