中国站长论坛

中国站长论坛 ›› 网络编程 ›› 求个mysql的查询语句

页码: 1

求个mysql的查询语句

- 菜菜2003 2008-07-30 20:58

有如下数据,我想查询  张三所回复的主题 也就是查后结果 是id1这条数据
 id title fid username
 1 测试 0 小明
 2 回复id1 1 张三
 3  回复id1 1 张三
以下是我的代码:

$sql=mysql_query("select id,title from test where id in (select fid from test where username='张三')")

可是发现速度很慢 不知道为什么 请大虾指点!

Re:求个mysql的查询语句

- 菜菜2003 2008-08-01 12:21

顶!!1

Re:求个mysql的查询语句

- gavin 2008-08-01 13:39

如果张三还回复了另一条主题,怎么办呢?

Re:求个mysql的查询语句

- 菜菜2003 2008-08-01 23:08

我就是要列出张三所回复的全部主题啊 现在是列出来了 就是速度有点慢 想请教大虾怎么弄比较合适

Re:求个mysql的查询语句

- hcmatthew 2008-08-02 01:48

速度慢应该是服务器的问题吧? 非要找原因我猜会不会是子查询的问题,mysql对子查询的支持是5。0才支持的吧。 会不会支持得不太好 

试试用联表查询
select distinct ori.id,ori.title from test as ori left outer join test as rep on ori.id=rep.fid where rep.username = '张三'

Re:求个mysql的查询语句

- parksungho 2008-08-08 10:34

帮你顶起。。。。

Re:求个mysql的查询语句

- 土改工作组 2008-08-17 23:11

select id,title from test where id in (select fid from test where username='张三')

你的id in.........是什么用途?
如果没有特殊用途就直接 select id,title from test where username='张三'

如果数据量大分几次取看看怎么样,limit x,y

Re:求个mysql的查询语句

- jurae 2008-09-08 17:41

俺不会. 不过应该和ASP的写法差不多吧!

Re:求个mysql的查询语句

- xinbi 2008-09-11 11:00

子查询的速度当然不快

Re:求个mysql的查询语句

- wxj_16740 2008-09-13 17:28

不好这样写。

页码: 1