获取两个表的结果
我有两个表“链接”和“类别”,如何从链接中获取 4 列,从类别中获取一列?
**Links**
_id
link_title
link_desc
link_date
**Categories**
_id
cat_title
cat_desc
我需要这样的单行 _id, link_title, link_desc, link_date, cat_title
然后在我的游标中使用它
private void fillData() {
Cursor linkCursor = mDbHelper.fetchAllLinks();
startManagingCursor(linksCursor);
String[] from = new String[]{ DbAdapter.LINK_TITLE, DbAdapter.LINK_DESC, DbAdapter.LINK_DATE, DbAdapter.LINK_ROWID, DbAdapter.CAT_DESC };
int[] to = new int[]{ R.id.title, R.id.content, R.id.date, R.id.headid, R.id.catdesc };
SimpleCursorAdapter links = new SimpleCursorAdapter(this, R.layout.linkrow, linkCursor, from, to);
//links.setViewBinder(new MyViewBinder());
setListAdapter(links);
}
我尝试了 SQL UNION 但它不起作用。
I got two tables "links" and "categories" how do i get 4 colunms from links and one from categories?
**Links**
_id
link_title
link_desc
link_date
**Categories**
_id
cat_title
cat_desc
i need a single row like this
_id, link_title, link_desc, link_date, cat_title
and then use this in my cursor
private void fillData() {
Cursor linkCursor = mDbHelper.fetchAllLinks();
startManagingCursor(linksCursor);
String[] from = new String[]{ DbAdapter.LINK_TITLE, DbAdapter.LINK_DESC, DbAdapter.LINK_DATE, DbAdapter.LINK_ROWID, DbAdapter.CAT_DESC };
int[] to = new int[]{ R.id.title, R.id.content, R.id.date, R.id.headid, R.id.catdesc };
SimpleCursorAdapter links = new SimpleCursorAdapter(this, R.layout.linkrow, linkCursor, from, to);
//links.setViewBinder(new MyViewBinder());
setListAdapter(links);
}
I tried SQL UNION but it dont worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要的称为联接。但要做到这一点,您需要提供两个 id,或者向链接表添加一个 Category_id 列。
或添加列后
更多信息:
What you want is called a join. But to do this you need to either give two ids, or add a category_id column to the Links-table.
or after adding the column
More information: