开发者

SQliteDatabase query construction problem in Android

开发者 https://www.devze.com 2023-03-09 13:20 出处:网络
I am trying to build a query in SQLite in Android. Query is very simple and looks like this: SELECT ifnull(object.icon_large, ifnull( object.image, item.IMG_DEF_COVE开发者_StackOverflowR))

I am trying to build a query in SQLite in Android. Query is very simple and looks like this:

SELECT    
        ifnull(object.icon_large, ifnull( object.image, item.IMG_DEF_COVE开发者_StackOverflowR))   

FROM 
        object , item 
WHERE  
        object.id_item = 1 AND item.id_item = 1;

I've tried to use SQLiteDatabase.query(), but it can be used only for one table. Any suggestions how to combine queries or how to join them, using Android SQLiteDatabases query's syntax?

Thanks in advance!!!


@fox you can use rawquery() instead of query example:

SQLiteDatabase mydatabase;
mydatabase.rawquery("select * from a, b where a.id=b.someid", null);

or can use querybuilder's setTable() method to specify the joins example

 builder.setTables(TABLEA+" LEFT JOIN "+TABLEB+" ON "+TABLEB+"."+KEY_ID+"="+TABLEA+"."+KEY_B_ID);


SELECT    
    ifnull(object.icon_large, ifnull(object.image, item.IMG_DEF_COVER))   
FROM 
    object 
JOIN
    item
ON
    object.id_item = item.id_item
WHERE  
    object.id_item = 1;

SELECT syntax

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号