Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Update and delete at the same time Postgres

I have a table of this kind

Table of items with price under 100

Prod_ID PRICE
1 45
2 67
3 89
4 91
5 23
6 98

Now I Want to write PostgresSQL command to update the price of each item increasing it by $10 and want to delete all the items with price more than $100

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

After the query, the table should be:

Prod_ID PRICE
1 55
2 77
3 99
5 33

How can I do this?

>Solution :

You can use update first and then delete.

UPDATE your_table_name set PRICE=PRICE + 10;
DELETE FROM your_table_name  WHERE PRICE > 100;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading