I have a table about employee with 3 columns like following code:
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + DEPT
+ " TEXT NOT NULL," + NAME + " TEXT NOT NULL," + CITY + " TEXT NOT NULL);");
now I just want to show em开发者_运维问答ployees in the same both DEPT and CITY(e.i both employees in HCM City and Sales department). How can I query to get it?
@DienTrinh, you had it right, note the spaces around AND
. That should work for you.
Cursor cursor = db.query(TABLE_NAME,
new String [] {_ID, NAME, DEPT, CITY },
DEPT +"=?" +" AND " + CITY +"=?",
new String[] {"Sales", "HCM" },
null, null, null);
The solution is:
SELECT * FROM Employess
WHERE DEPT='Sales' COLLATE NOCASE AND City='HCM' COLLATE NOCASE
SELECT * FROM Employees WHERE DEPT='Sales' AND City='HCM'
精彩评论