0
 Cursor cursor = db.rawQuery("SELECT id,lastname,status FROM people WHERE " + "id = "+ IncomingiD +" FROM people WHERE status =100 ); ",null);

I want to access to "status=100 and id=incomingid" of my people table. I wrote above snipped code but I am getting an error below.... What is wrong with that query ? Could you please help me ?

E/Error(996): Error while openining peopleandroid.database.sqlite.SQLiteException: near "FROM": syntax error: , while compiling: SELECT id,lastname,status FROM people WHERE  id = 1 FROM places WHERE status =100 ); 

3 Answers 3

1

You have the FROM people part twice in your query :

  • First, at the correct place, between the select and where clause
  • And then, a second time, after the first condition in the where clause.

Also, note that you have where twice in your query -- the two condition should be separated by and and, and not a second where.

Oh, and it also seems that you have a closing ) at the end of your query?


Basically, your query looks like this :

SELECT id,lastname,status 
FROM people 
WHERE id = ....
FROM people 
WHERE status =100 
); 

But it should be looking like that :

SELECT id,lastname,status 
FROM people 
WHERE id = ....
    and status = 100 


In the end, I'm guessing your Java code should look a bit like this :

Cursor cursor = db.rawQuery("SELECT id, lastname, status FROM people WHERE id = " + IncomingiD + " AND status = 100",null);
Sign up to request clarification or add additional context in comments.

Comments

0

your query is wrong. there can be only one FROM in sql statement.

try this:

cursor = db.rawQuery("SELECT id,lastname,status FROM people WHERE " + "id = "+ IncomingiD +" AND status =100 ); ",null);

Comments

0

The query should read

 Cursor cursor = db.rawQuery("SELECT id,lastname,status FROM people WHERE " + "id = "+ IncomingiD +"AND status =100 ); ",null);

1 Comment

@Co Koder - that would be because he left out + " after IncomingiD.

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.