View Full Version : MyChenQL, part 5
filburt1
12-31-2002, 11:21 PM
How can I make this into valid SQL for MySQL (i.e., dump the nested query):
SELECT pagetext FROM post WHERE threadid =
(SELECT threadid FROM thread WHERE forumid = 18 ORDER BY dateline DESC LIMIT 1)
ORDER BY dateline ASC LIMIT 1
English: select the pagetext from the first post in the most recent thread in forum 18.
okrogius
01-01-2003, 09:36 AM
SELECT post.pagetext, thread.dateline, thread.forumid FROM post, thread WHERE thread.forumid=18 && post.threadid=thread.threadid ORDER BY thread.dateline ASC LIMIT 1;
Try that.
Chris M
01-01-2003, 10:03 AM
SELECT post.*, thread.* FROM post LEFT JOIN thread ON post.threadid=thread.threadid WHERE thread.forumid=18 ORDER BY thread.dateline ASC LIMIT 1;
:)
Satan
filburt1
01-01-2003, 03:08 PM
Now which one would be the least server-intensive? I vaguely remember Chen saying something about never joining the post and thread tables...
Herman
01-01-2003, 05:14 PM
xD you could always use the Union (i just learnt it an hour ago) it joins multiple queries to one and really increases load time...
Xenon
01-01-2003, 05:50 PM
@filburt: i'd use Codenames version, i think it's faster here.
Joining is needed for other issues.
filburt1
01-01-2003, 06:40 PM
Okay, will try :)
okrogius
01-01-2003, 08:21 PM
Never use SELECT * unless you need it. Of course, there is an exception - if you lack common sense it won't matter ;).
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.