- 论坛徽章:
- 1
|
原帖由 115300111 于 2007-3-29 14:32 发表
$sql="SELECT author, subject FROM pw_threads WHERE tid=$tid LIMIT 1";
$sql="SELECT content FROM pw_tmsgs WHERE tid=$tid LIMIT 1";
$sql="SELECT author, subject, content FROM pw_posts WHERE tid=$tid ORDER BY pid limit 0,20";
可以合成,但是下面的合成方法,只是从合成的角度来考虑的,并没有考虑效率的问题。
1. 读取出来的信息,是否有主键呢?我们假设为post_id
2. sql1、sql2合成,很好做:
- $sql = "SELECT author, subject, content FROM pw_threads WHERE tid=$tid LIMIT 1";
复制代码
3. 2和sql3合成
- $sql = "SELECT author, subject, content FROM pw_threads WHERE
- post_id = ( SELECT post_id FROM pw_threads WHERE tid=$tid LIMIT 1 )
- OR
- post_id IN ( SELECT post_id FROM pw_posts WHERE tid=$tid ORDER BY pid limit 0,20 )
- ORDER BY pid
- ";
复制代码 |
|