Android中的内部联接查询问题在Sqlite查询中遇到麻烦

时间:2013-08-05 11:16:11

标签: android sqlite inner-join

我遇到麻烦我在sqlite中有2个表并且想要两个字段但是我没有任何东西。我已经尝试了很多堆栈溢出但没有人为我工作.. 我的查询是这样的 -

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;
        }

当我尝试使用相同的表进行左外连接时,它的工作正在进行..

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

但是我需要来自两个表的所有数据。请帮帮我......

0 个答案:

没有答案