Issue in Inner Join Query in Android | Trouble in Sqlite query

蓝咒 提交于 2019-12-11 07:43:49

问题


I am in trouble I have 2 table in sqlite and want both field from them but I did not got any thing. I have tried a lot on stack overflow but no one is work for me.. My query is something like that-

public List<HeadItemGroup> getAllExpense() {
            List<HeadItemGroup> expenseList = new ArrayList<HeadItemGroup>();
            db = sqlHp.getReadableDatabase();
            String selectquery = "SELECT table_expense.item_id AS ID,table_item.item_id AS ID2,* FROM table_expense INNER JOIN table_item ON table_expense.item_id=table_item.item_id";
            System.out.println("selectquery value..."+selectquery);
            cursor = db.rawQuery(selectquery, null);

            while (cursor.moveToNext()) {
                    HeadItemGroup record = new HeadItemGroup();
                    record.setExpId(cursor.getInt(cursor.getColumnIndex(EXPENCE_ID)));
                    record.setItemId(cursor.getInt(cursor.getColumnIndex(ITEM_ID)));
                    record.setHeadId(cursor.getInt(cursor.getColumnIndex(HEAD_ID)));
                    record.setDate(cursor.getString(cursor.getColumnIndex(EXPENCE_DATE)));
                    record.setPrice(cursor.getString(cursor.getColumnIndex(EXPENCE_PRICE)));
                    record.setLocationLat(cursor.getString(cursor.getColumnIndex(LOCATION_LAT)));
                    record.setLocationLon(cursor.getString(cursor.getColumnIndex(LOCATION_LON)));
                    record.setLocationName(cursor.getString(cursor.getColumnIndex(LOCATION_NAME)));
                    record.setCurrency(cursor.getString(cursor.getColumnIndex(CURRENCY_SYMBOL)));
                    record.setDescription(cursor.getString(cursor.getColumnIndex(DESCRIPTION)));
                    record.setItemName(cursor.getString(cursor.getColumnIndex(ITEM_NAME)));
                    record.setGroupId(cursor.getInt(cursor.getColumnIndex(GROUP_ID)));

                    expenseList.add(record);
                    System.out.println("total value value**************"+ cursor.getString(cursor.getColumnIndex(EXPENCE_PRICE)));
                    System.out.println("total value value**************"+ cursor.getString(cursor.getColumnIndex(ITEM_NAME)));
                    System.out.println("total value value**************"+ cursor.getString(cursor.getColumnIndex(GROUP_ID)));
            }

            return expenseList;
        }

And when I am trying with same table for left outer join it's work..

String selectquery="select exp_id as _id, * from table_expense d left outer join table_item  u on ( d.item_id=u.item_id)";

But i need all data from both table. Please help me...

来源:https://stackoverflow.com/questions/18056839/issue-in-inner-join-query-in-android-trouble-in-sqlite-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!