开发者

How can i write join query in android sqlite?

Hi, I am new to android. I want to write query for join in sqlite. My code is -

public Cursor SearchCategory(SQLiteDatabase db){
        //return  db.query("category_master", null, "status = 'Active'", null, null, null, null);

        String Category_Sql = " select category_master.*,count(*) as cnt from product_master " +
                            "   left join category_master on produc开发者_如何学编程t_master.category_id = category_master.category_id " +
                            "   where category_master.status = 'Active' group by category_master.category_id having cnt > 0 ";
        return db.query(Category_Sql);
    }

but it generate error. Where am I wrong?


It would have helped more if you could cite the error description.

Try running the query first in Portable SQLite explorer


you can use rawQuery

db.rawQuery("Select a.column1,b.column1 FROM table1 a JOIN table2 b ON a._id=b._id", null);

it should work

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜