I have 2 tables and like to update one of them with the values from the other.
software --------- id , purchprice softwarecost ------------ id , purchprice
I've tried these queries but, SQLite doesn't support JOINS with UPDATE.anybody out there who can come up with a query for this.thanks for your help.
UPDATE software SET software.purchprice=softwarecost.purchprice WHERE software.id=softwarecost.id UPDATE software INNER JOIN softwarecost on software.id=softwarecost.id SET software.purchprice=softwarecost.purchprice
The most easiest and common way is to use join clause in the update statement and use multiple tables in the update statement. Here we can see that using join clause in update statement. We have merged two tables by the use of join clause.
First, specify the table where you want to update after the UPDATE clause. Second, set new value for each column of the table in the SET clause. Third, specify rows to update using a condition in the WHERE clause. The WHERE clause is optional.
SQLite Joins clause is used to combine records from two or more tables in a database. A JOIN is a means for combining fields from two tables by using values common to each.
Returns the current database page size, in bytes.
This will work
UPDATE software SET purchprice = (SELECT purchprice FROM softwarecost WHERE id = software.id) where EXISTS (SELECT purchprice FROM softwarecost WHERE id = software.id)
Here we use exists because without that the query will set software.purchprice to null if no "correlated" row is found.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With