Note that there are some explanatory texts on larger screens.

plurals
  1. POIn sqlite3: copy a column from one table to another table
    text
    copied!<p>There are several other stackoverflow inquiries about this topic, but none of them have a satisfactory answer.</p> <p>I have a table BeerReviews, which is missing a column (review_text), and another table BeerReviewsWithText which is missing a different column (brewery_name). Otherwise the table rows are ordered the same way, so I would like to simply append the brewery_name column from BeerReviews into BeerReviewsWithText.</p> <p>I launch sqlite3 as:</p> <pre><code>sqlite3 beer_rewiews_with_text.sqlite </code></pre> <p>Then I attach the beer reviews table via:</p> <pre><code>attach 'beer_reviews.sqlite' as BR </code></pre> <p>I added an empty column to BeerReviewsWithText via:</p> <pre><code>alter table BeerReviewsWithText add column beer_brewername varchar; </code></pre> <p><a href="https://stackoverflow.com/questions/5029391/copy-column-data-from-one-table-to-another-in-sqlite/5033489#5033489">Multiple</a> <a href="https://stackoverflow.com/questions/2361921/select-into-statement-in-sqlite/2361961#2361961">other</a> questions suggest using insert to fill the column, but this appends new rows to the table, populating only the beer_brewername column.</p> <pre><code>insert into BeerReviewsWithText(beer_brewername) select brewery_name from BeerReviews; </code></pre> <p>Instead, an update seems to fill in the null values, but when I run the following (similar to <a href="https://stackoverflow.com/questions/1559789/copy-data-between-two-table-in-sqlite">another question's answer</a>) all of the beer_brewername values are identical:</p> <pre><code>update BeerReviewsWithText set beer_brewername=(select brewery_name from BR.BeerReviews); </code></pre> <p>This seems like strange behavior since I get the expected list of brewery names when I run:</p> <pre><code>select brewery_name from BR.BeerReviews limit 50; </code></pre> <p>I'm new to sqlite, so can someone explain what I'm doing incorrectly?</p>
 

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