Postgresql delete multiple rows from multiple tables
问题 Consider 2 or more tables: users (id, firstname, lastname) orders (orderid, userid, orderdate, total) I wish to delete all users and their orders that match first name ' Sam '. In mysql, I usually do left join. In this example userid is unknown to us. What is the correct format of the query? 回答1: http://www.postgresql.org/docs/current/static/sql-delete.html DELETE FROM orders o USING users u WHERE o.userid = u.id and u.firstname = 'Sam'; DELETE FROM users u WHERE u.firstname = 'Sam'; You can