Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7987743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:14:11+00:00 2026-06-04T12:14:11+00:00

I have a SQLite table called Price like this: date, productId, price ———————- 20120601,

  • 0

I have a SQLite table called Price like this:

date,     productId, price
----------------------
20120601, 10       , 10.1
20120601, 20       , 20.1
20120602, 10       , 0
20120602, 20       , 0
20120602, 30       , 0

The table is created with this statement:

CREATE TABLE "Price" ("date" INTEGER NOT NULL , "productId" INTEGER NOT NULL , "price" DOUBLE, PRIMARY KEY ("date", "productId"))

I want to fill the price of date==20120602 with the price of the same product in the previous date.

i.e I want the table turn into like this:

date,     productId, price
----------------------
20120601, 10       , 10.1
20120601, 20       , 20.1
20120602, 10       , 10.1
20120602, 20       , 20.1
20120602, 30       , 0

So I tried this SQL statement:

UPDATE Price New SET New.price = 
    (SELECT old.price FROM Price Old WHERE New.date == 2 AND Old.date == 1 AND New.productId == Old.productId)

But SQLite gave me an error near dot.

Than I tried this statement:

UPDATE New Set New.Price = Old.Price
FROM Price New, Price Old
WHRER ......

SQLite gave me an error near FROM.

I double checked SQLite’s SQL Syntax but found no lucky. Even I never tried so, I think both statements would work as expected in MS SQL Server. The first statement might work if New and Old are too different tables, but I need them in same table.

I really don’t want to write a for loop to update once a line in my C++ code, I need advice on the right way to achieve this in SQLite.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:14:12+00:00Added an answer on June 4, 2026 at 12:14 pm

    I myself have experienced this. Just remove word New after UPDATE Price and wherever you use New.something change to Price.something. I am sure there is a much nicer solution, but it works.

    updated with code snippet from comments…

    UPDATE Price 
    SET
    price = (SELECT old.price FROM Price Old WHERE Old.date = 1 AND price.productId = Old.productId) 
    WHERE price.date = 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a SQLite database via SQLiteManager. I have a table called Envelopes, and
I have an sqlite table with Date of Birth. I would like to execute
Hi all i have the following table called student in SQLite database. this is
I have a SQLite table called posts . An example is shown below. I
So I have a local SQLite table breadcrumbs being created on the Android device.
I have a table in SQLite: CREATE TABLE test_results(timestamp TEXT, npass INTEGER, nfails INTEGER)
i have a table in sqlite database like following. id status ============= x 0
I have a simple SQLite table called message: sequence INTEGER PRIMARY KEY type TEXT
I am creating a SQLite database for my iPhone projects. I have table called
Okay, so I have a (SQLite) table called log wherein one column (time) is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.