Mun*_*hoo 1 sqlite android android-cursor android-sqlite
我的查询是 SELECT DefaultId FROM tblsample where ('567' = DefaultId) || ('567' = Name)
在上面的查询中
table name = tblsample
Column Names = DefaultId , Name
Input Value = 567
Run Code Online (Sandbox Code Playgroud)
现在我想检查这个值在表中的哪一列中可用并返回它的DefaultId。我能够在 Sqlite 中实现这一点,想知道是否还有更好的方法来优化查询和在 android 中使用
database.query(boolean distinct, String table, String[] columns,String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
Run Code Online (Sandbox Code Playgroud)
我必须在android中使用哪个查询。
使用这个片段:
String table = "tblsample";
String selection = "DefaultId =? OR Name=?";
String[] selectionArgs = new String[]{"567"};
String[] projection = new String[]{"DefaultId","Name"}; // if you want to fetch only these two columns
Run Code Online (Sandbox Code Playgroud)
在您之前database.query:
database.query(true, table, projection, selection, selectionArgs, null, null, null, null);
Run Code Online (Sandbox Code Playgroud)
如果需要,请更改distinct、limit、orderBy、having和groupBy的值。
| 归档时间: |
|
| 查看次数: |
2854 次 |
| 最近记录: |