我正在使用内容提供程序在sqlite中存储数据,并使用游标适配器在listview中显示数据。 我有3张桌子
1)Leads- [_ id,name,....]
2)LeadsAttachment- [_id,format,LeadId,....](LeadId是FK to _id PK of Leads表)
3)LeadsProduct- [_ id,pname,LeadId,....](LeadId是FK to _id PK of Leads表)
现在我正在使用SQLQueryBuilder执行Leads和LeadsAttachment之间的左连接
SQLiteQueryBuilder leadsWithAttachmentQueryBuilder = new SQLiteQueryBuilder();
leadsWithAttachmentQueryBuilder.setTables(
MBenzContracts.LeadsEntry.TABLE_NAME + " LEFT JOIN " +
MBenzContracts.LeadAttachmentEntry.TABLE_NAME +
" ON " + MBenzContracts.LeadAttachmentEntry.TABLE_NAME +
"." + MBenzContracts.LeadAttachmentEntry.COLUMN_Lead_ID +
" = " + MBenzContracts.LeadsEntry.TABLE_NAME +
"." + MBenzContracts.LeadsEntry._ID);
我将如何在SQLiteQueryBuilder中一起执行2个左连接,以便我得到 所有来自Leads的记录以及LeadsAttachment和LeadsProduct
答案 0 :(得分:0)
想通了,非常简单
leadsWithProductAndAttachmentQueryBuilder.setTables(
MBenzContracts.LeadsEntry.TABLE_NAME + " LEFT JOIN " +
MBenzContracts.LeadProductEntry.TABLE_NAME +
" ON " + MBenzContracts.LeadProductEntry.TABLE_NAME +
"." + MBenzContracts.LeadProductEntry.COLUMN_Lead_ID +
" = " + MBenzContracts.LeadsEntry.TABLE_NAME +
"." + MBenzContracts.LeadsEntry._ID + " LEFT JOIN " +
MBenzContracts.LeadAttachmentEntry.TABLE_NAME +
" ON " + MBenzContracts.LeadAttachmentEntry.TABLE_NAME +
"." + MBenzContracts.LeadAttachmentEntry.COLUMN_Lead_ID +
" = " + MBenzContracts.LeadsEntry.TABLE_NAME +
"." + MBenzContracts.LeadsEntry._ID);