lundi 15 février 2016

sqlite update with query of multiple fields from various tables

I have the following tables:

book_tbl:
book_instance_id | book_type_id | library_instance_id | location_id | book_index
1 | 70000 | 2 | 0 | 1
2 | 70000 | 2 | 0 | 2
3 | 70000 | 2 | 0 | 3
4 | 70000 | 3 | 0 | 1
5 | 70000 | 3 | 0 | 2
6 | 70000 | 3 | 0 | 3
7 | 70000 | 4 | 1 | 1
8 | 70000 | 4 | 1 | 2
9 | 70000 | 4 | 1 | 3

and

library_tbl:
library_instance_id | library_type_id | location_id
2 | 1000 | 0
3 | 1001 | 0
4 | 1000 | 1

I would like to update the field book_type_id in book_tbl table only for the first element (index) in library_type_id 1000

To retrieve this information I used sqlite query:

SELECT * FROM ( ( SELECT * FROM library_tbl WHERE library_type_id=1000 ) t1 join book_tbl t2 on t1.location_id=t2.location_id AND t1.library_instance_id=t2.library_instance_id AND book_index=1 )

How could I use the query above with UPDATE query to update rows 1 and 7:

UPDATE book_tbl SET book_type_id=15000 WHERE ????

Aucun commentaire:

Enregistrer un commentaire