[已解决问题] 数据库问题
提问时间: 2008-05-16 14:14
悬赏分:50 浏览:113 次

 我要获取日志表的内容,条件是根据标签来获取,不知道怎么写了.请帮忙

 表一: [blog_Content] 日志表: 

字段:blog_id ,cate_Id,blog_Title,blog_Entry,blog_Content,blog_Tbs 等

 表二: [blog_tag] 标签表:

字段:tag_Id,tag_Label,tag_Used

 表三: [blog_Blogtag] 关联表:

字段:seq_Id,blog_Id,tag_Id

 比如.我根据分类来获取日志列表就是这样写: 因为在一个表中

   "select * from blog_Content where cate_id=@CataID ";

 


提问者:lonely - 初学一级

问题补充: /// <summary>
/// 获取文章列表 根据分类
/// </summary>
/// <param name="CreateUser"></param>
/// <returns></returns>
public override IList<Content> GetTopContent(int CatId)
{
string strGetTopContent = "SELECT * FROM blog_Content where Cat_id=@CatId";
IDataReader dr = SQLiteHelper.ExecuteReader(strGetTopContent, null);
IList<Content> list = new List<Content>();

while (dr.Read())
{
list.Add(Model(dr));
}
dr.Close();
return list;
}

最佳答案
根据标签ID获取日志:
select * from [blog_Content] where blog_id in (select blog_id from blog_Blotag where tag_Id=@tagId)
根据标签获取日志:
select * from [blog_Content] where blog_id in     (select blog_id from blog_Blotag where tag_Id=(select tag_Id from blog_tag where tag_label=@taglabel))
2008/5/16 14:35:31 回答者:侯垒


提问者对于答案的评价:谢谢,真能套啊。select * from [blog_Content] where blog_id in (select blog_id from blog_Blotag where tag_Id=(select tag_Id from blog_tag where tag_label=@taglabel)) 回答者:侯垒 5/16/2008 2:35:31 PM
其它回答(1)
select bc.* from blog_Content bc,[blog_tag]  bt,[blog_Blogtag] bbt
where  bt.tag_Label="...." and bt.tag_Id = bbt.tag_Id and bbt.blog_Id = bc.blog_Id
1个月前   回答者:wingoo - 小虾三级
评论
   您需要登录以后才能回答!
我的问题    我要提问


快到期问题

> 问题排行榜

有不合适内容,建议去除