0

I am trying to update one column of second table based on column of first table. I want to update column lid in record table with values of cid column of detail table based on rid (detail table) and crid (record table).

public String updateId() {

        String selectQuery = "UPDATE record SET lid = (SELECT detail.cid FROM detail WHERE detail.rid = record.crid" ;

        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);

        return null;

    }

Log says:

  android.database.sqlite.SQLiteException: near "crid"

Activity - on button click, using below code to update table:

 dh.updateId();
4
  • why this has been downvoted ? Commented Nov 4, 2015 at 7:33
  • hey check your query it is wrong may be you missing something parantheses or something Commented Nov 4, 2015 at 7:35
  • lid, cid, rid, crid, ... why don't you use meaningful column names? It's hard to follow the logic, otherwise. And in the future, you'll have problems in maintaining your own logic, even if today it appears clear to your eyes (and yours only). Commented Nov 4, 2015 at 7:50
  • 1
    sure i will take care and i have done with update... @FrankN.Stein Commented Nov 4, 2015 at 7:55

1 Answer 1

3

You are missing a closing parenthesis in your statement.

"UPDATE record SET lid = (SELECT detail.cid FROM detail WHERE detail.rid = record.crid)" ;
                                                                                      ^
Sign up to request clarification or add additional context in comments.

3 Comments

I have ticked your answer as useful and will accept in 10 mins, now i am not getting issue, but still not able to update column, please check'
@Sophie Without knowing anything about your schema, I cannot tell you why the statement does not do what you expect. It's possible the statement is perfectly fine but your data is not--I have no way to know. Also, you should not be using rawQuery() to execute update statements. SQLiteDatabase has an update() method for that.
ok can you show me the way of executing rawQuery() I guess this is the only reason...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.