Note that there are some explanatory texts on larger screens.

plurals
  1. POSqlite statement using UPDATE, SET, WHERE, and LIKE isn't updating all of the records
    primarykey
    data
    text
    <p>I am using the 'Execute SQL' feature in sql gui tool 'SQLite Database Browser 2.0 b1.'</p> <p>I am not sure if the problem I am facing is because of a bug within the Browser or if my SQL is just wrong. I do know that I have found several bugs within the Browser tool.</p> <p>Anyhow. Here is the problem I am dealing with currently...</p> <p>I have two tables in a database:</p> <pre><code>TOYS ------------------------------ TOY_ID TOY_DESC ------------------------------ 1 Green truck, plastic 2 Doll, plastic, wood 3 Stuffed cloth animal 4 Board game cardboard and plastic etc ..... MATERIALS ----------------------------- TOY_ID PLASTIC ----------------------------- 1 2 3 4 etc ...... </code></pre> <p>I am trying to update the MATERIALS table so that IF the TOY_DESC that corresponds with the matching TOY_ID in the TOYS table, contains the word 'plastic', that it should insert the number 1 into the PLASTIC column in the MATERIALS table. This is what I have tried:</p> <pre><code>UPDATE MATERIALS SET PLASTIC = 1 WHERE TOY_ID = (SELECT TOY_ID FROM TOYS WHERE TOY_DESC LIKE '%plastic%'); </code></pre> <p>when I tried this it did nothing.</p> <p>then I tried...</p> <pre><code>UPDATE MATERIALS SET PLASTIC = 1 WHERE TOY_ID = (SELECT TOY_ID FROM TOYS WHERE TOY_DESC LIKE "%plastic%"); </code></pre> <p>which then gave me:</p> <pre><code>MATERIALS ----------------------------- TOY_ID PLASTIC ----------------------------- 1 1 2 3 4 etc ...... </code></pre> <p>then I tried...</p> <pre><code>UPDATE MATERIALS SET PLASTIC = 1 WHERE TOY_ID = (SELECT TOY_ID FROM TOYS WHERE TOY_DESC LIKE '%plastic,%'); </code></pre> <p>and that updated only one more record: </p> <pre><code>MATERIALS ----------------------------- TOY_ID PLASTIC ----------------------------- 1 1 2 1 3 4 etc ...... </code></pre> <p>But still, it didn't update ALL of the records that contained the word plastic in the description!! I don't get it. why aren't all the records updating? I could understand if there was some other type of symbol or character on the end of the words, but there isn't. it's like exactly the same word in the other descriptions and they are ALL being skipped! I am further confused as to why the update didn't work at ALL until I replaced the single quotations with double quotations. Is this because of a difference in database type (sqlite vs. mysql)?</p> <p>EDIT**: </p> <p>I tried the suggestion from the poster below to break it down further to see where the problem might be. When I just do:</p> <pre><code>SELECT TOY_ID FROM TOYS WHERE TOY_DESC LIKE '%plastic%' </code></pre> <p>I successfully get a list of all the records that contain the word plastic in the description. So the LIKE statement isn't the problem. The question now is how do I get this to be reflected in the MATERIALS table? </p> <p>I'm guessing I somehow need a loop for each match?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload