首页 > 关于数据库多表查询的问题?

关于数据库多表查询的问题?

目前有三张表
topic话题表 id title
tagsmap对应关系表 id tagsid topicid
tags标签表 id tagsname

现在需要查询某个标签下的前几条话题记录。

select title from topic where id in (select topicid from tagsmap where tagsid="10000")

这种查询发现查询比较慢。

这种写法有什么问题?请问如何优化查询比较好!希望能讨论。


只是一般程度的优化的话:
select title from topic t left join tagsmap m on m.topicid = t.id where m.tagsid = "10000"
数据量在几万到几十万基本上这个性能都可以接受,当然记得tagsmap里面的tagsid加上索引

【热门文章】
【热门文章】