Is it possible to use more than one related queries together in MySQL or PostreSQL? [duplicate]
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
精彩评论