I need one help regarding the My Sql Query..
My Table is like this
_id studid recid arrival
834 29 436 12:04
835 29 437 12:19
836 29 438 12:35
837 29 439 12:43
Now I need to compare the id’s of recid 436 and recid 439
Exactly like this
_id(recid(436)) < _id(recid(439)) // 834 < 837 (true)
I need query for this..
I tried like this..
public boolean Check(String tid,String src,String dest)
{
Cursor c1 = this.db.query(TABLE_NAME_2, new String[] { "_id" },
"_studId = \"" + src +"\" AND _recId = \"" + tid+"\"" , null, null, null, null);
Cursor c2 = this.db.query(TABLE_NAME_2, new String[] { "_id" },
"_studId = \"" + dest +"\" AND _recId = \"" + tid+"\"" , null, null, null, null);
int srcid = 0;
int destid = 0;
if (c1.moveToFirst())
{
do {
srcid = Integer.parseInt(c1.getString(0));
} while (c1.moveToNext());
}
if (c1 != null && !c1.isClosed()) {
c1.close();
}
if (c2.moveToFirst())
{
do {
destid = Integer.parseInt(c2.getString(0));
} while (c2.moveToNext());
}
if (c2 != null && !c2.isClosed()) {
c1.close();
}
if(srcid < destid)
{
return true;
}
else
{
return false;
}
}
which is returning correct results when checking like this
System.out.println(dh.Check("29", "436", "439")); // returns true.
But i think its not correct procedure as there will be multiple records.So if there are 50 records then i have to execute this function 50 times. So I need a simple query for this..
If any body have experience like this. help me please..
Thanks in Advance.
You could use a query like this, which returns 0 or 1:
To make repeated executions more efficient, use a pre-compiled statement, which you can execute multiple times with different parameters: