Replies: 9 comments 3 replies
|
Missing a WHERE clause. Somehow you'll need to identify which books to apply the update to. |
|
I was looking for too complicated ...
|
|
Update queries can be applied to supersets or subsets. |
|
Huh? Someone is confused. UPDATE table SET field_a = field_b || field_c will set field_a to CONCAT(field_b, field_c) (assuming text) for row 0, row 1, etc. |
|
UPDATE table SET field_a = (SELECT ...) is not the solution you're looking for. Since the UPDATE of field_a can only be applied to a specific row, the UPDATE must select the first value from the inner SELECT. That is, row 0's field_a can only have one value; not all of the values in the table. |
|
Don't perform an inner select. UPDATE field = another_field with an optional WHERE. You're updating a single table. The inner select doesn't have a WHERE clause. It's like updating all books to be like one book. Which book? Well, the first one the SELECT discovers. You want to set a book's title to the concatenation of its title with its author. The UPDATE will do that without a WHERE clause because it's smart. UPDATE book SET title = title || author. |
|
sqlite> update book set title = title || author; |
|
SQL is very intuitive. Even the exceptions are self-explanatory when you think about them. SQL is Smart | Simple | Structured | Sophisticated Query Language. |

Uh oh!
There was an error while loading. Please reload this page.
I'm trying to update the callnumber field with 2 pieces of information found in location and authors.
the SELECT command gives the right results
SELECT SUBSTR(location, 0, INSTR(location, '-')) || ' ' || SUBSTR(author,0,4) FROM book
But when I want to go to the UPDATE step, it copies me the same value for all the books
UPDATE book SET callnumber = (SELECT SUBSTR(location, 0, INSTR(location, '-')) || ' ' || SUBSTR(author,0,4) FROM book)
Can you please give me some hints?
Thank you in advance.
All reactions