开发者

Is it possible to use more than one related queries together in MySQL or PostreSQL? [duplicate]

开发者 https://www.devze.com 2023-04-13 06:06 出处:网络
This question already has answers here: 开发者_JS百科Insert into select and update in single query
This question already has answers here: 开发者_JS百科 Insert into select and update in single query (3 answers) Closed 9 years ago.

I want to use different queries such as update, select and etc. Is it possible to combine them in one query? And how?


If you need to get the "result" of an UPDATE, DELETE or INSERT query in PostgreSQL, you can use the returning clause:

DELETE FROM my_table
WHERE some_id = ...
RETURNING *;

would return all rows that were delete by that statement. Likewise with UPDATE:

UPDATE my_table 
   SET column_1 = some_value,  
       column_2 = some_other_value
WHERE some_id = ...
RETURNING *;

would return all updated rows with the new values.

I don't think something like this is possible in MySQL though.


You can use stored procedures for wrap your functionality, check these documentation:

http://net.tutsplus.com/tutorials/an-introduction-to-stored-procedures/

http://www.eioba.com/a/1ign/a-basic-introduction-to-postgres-stored-procedures

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号