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 employees in the same both DEPT and CITY(e.i both employees in HCM City and Sales department). How can I query to get it?
This SQLite WHERE clause example uses the WHERE clause to define multiple conditions, but instead of using the AND Condition, it uses the OR Condition. In this case, this SELECT statement would return all employee_id, last_name, and first_name values from the employees table where the employee_id is 1 or 2.
To query data from multiple tables, you use INNER JOIN clause. The INNER JOIN clause combines columns from correlated tables. Suppose you have two tables: A and B. A has a1, a2, and f columns.
SQLite allows multiple processes to have the database file open at once, and for multiple processes to read the database at once. When any process wants to write, it must lock the entire database file for the duration of its update. But that normally only takes a few milliseconds.
@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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With