开发者

query problems with order by rand

开发者 https://www.devze.com 2023-02-03 21:57 出处:网络
$totalrows = 10; $sql = \"SELECT posts.Tags as tags, posts.OwnerUserId as postsid, posts.Id as postid,
$totalrows = 10;

$sql = "SELECT 
 posts.Tags as tags, 
 posts.OwnerUserId as postsid, 
 posts.Id as postid, 
 posts.Body as body, 
 posts.Title as title, 
 users.Id as us开发者_运维知识库erid, 
 users.DisplayName as usersname  
FROM posts 
JOIN users ON posts.OwnerUserId = users.Id 
WHERE posts.Title != '' order by rand() asc limit " .  $totalrows;

$r = mysql_query($sql) or die(mysql_error());

Any suggestion to speed php?


See this presentation from Bill Karwin. Slide 142 and onwards.

http://www.slideshare.net/billkarwin/sql-antipatterns-strike-back


Check this... $limit = 10; $start = 0; $sql = "SELECT posts.Tags as tags, posts.OwnerUserId as postsid, posts.Id as postid, posts.Body as body, posts.Title as title, users.Id as userid, users.DisplayName as usersname
FROM posts JOIN users ON posts.OwnerUserId = users.Id WHERE posts.Title != '' order by rand() asc limit " . $start . " , " . $limit;

$r = mysql_query($sql) or die(mysql_error());

0

精彩评论

暂无评论...
验证码 换一张
取 消