Thank you very much Dan. On Fri, 2008-10-17 at 14:10 +0700, Dan wrote: > On Oct 17, 2008, at 1:43 PM, Lloyd wrote: > > > Hi, > > > > Lets assume a table having following data > > > > No. Name Address > > ======================== > > 1 A addrA > > 2 B addrB > > 3 C addrC > > 4 B addrB1 > > > > I want to update the filed 'Address' based on field 'Name'. But if > > there > > are multiple table entries (The case of B), I just want to update the > > last entry in the table. How can I write a query for this? > > > > My present query is > > > > update mytab set Address="addr" where name="B" > > If you are using version 3.6.4 and compile with > SQLITE_ENABLE_UPDATE_DELETE_LIMIT, then you can use the new > syntax: > > UPDATE mytab SET Address='addr' WHERE name='B' ORDER BY rowid DESC > LIMIT 1; > > Otherwise, you have to do: > > UPDATE mytab SET Address='addr' WHERE rowid = (SELECT max(rowid) > FROM mytab WHERE name = 'B'); > > > Dan. > > > > > > > > > > > > The output of this query would be > > > > No. Name Address > > ======================== > > 1 A addrA > > 2 B addr > > 3 C addrC > > 4 B addr > > > > But the Output we want is > > > > No. Name Address > > ======================== > > 1 A addrA > > 2 B addrB > > 3 C addrC > > 4 B addr > > > > > > If my question is not clear, I am ready to explain it more... > > > > > > > > Thanks, > > Lloyd > > > > > > > > ______________________________________ > > Scanned and protected by Email scanner > > _______________________________________________ > > sqlite-users mailing list > > sqlite-users@sqlite.org > > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
______________________________________ Scanned and protected by Email scanner _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users