-2

I have two tables in my sqlite database, with a column name as in both tables solution, solutionimage, id saying tableA and tableB. I want to, copy from tableB solution, solutionimage to tableA matching the id in both table respectively, how to do it?

I have google it and tried but i didnt get it.. Any one help me. Thanks a lot in advance.

Make it Simple
  • 1,832
  • 5
  • 32
  • 57
  • 2
    With over 100 posts on SO you can sure do better. Please add more detail to your question. – juergen d Oct 15 '13 at 12:13
  • 1
    Clarify your question it is not clear at all what you are doing; question title is saying `ADD data` but phrasing of your question could imply you actually want to update entries in tableB with values from tableA? What is it? – DrCopyPaste Oct 15 '13 at 12:21

1 Answers1

6

Ideally you would want to join the table you are updating to the other table where you take the values from.

But I just read that JOINS in UPDATES are not allowed in SQLITE so subqueries are the way to go I suppose:

UPDATE tableB
    SET
      Solution = (SELECT Solution FROM tableA WHERE ID = tableB.ID),
      SolutionImage = (SELECT Solution FROM tableA WHERE ID = tableB.ID);

See this fiddle for example output.

Community
  • 1
  • 1
DrCopyPaste
  • 4,023
  • 1
  • 22
  • 57
  • Thanks a lot.. I have done a mistake.. i have enter it in WHERE ID = ID This is my mistake i have changed into like your query its worked fine....Thanksss.... – Make it Simple Oct 16 '13 at 06:13