dbTalk Databases Forums  

converting a MySQL 4.1 subquery to something that'll work with MySQL 4.0

comp.databases.mysql comp.databases.mysql


Discuss converting a MySQL 4.1 subquery to something that'll work with MySQL 4.0 in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
yawnmoth
 
Posts: n/a

Default converting a MySQL 4.1 subquery to something that'll work with MySQL 4.0 - 07-22-2006 , 07:15 PM






Say I have the following SQL query:

UPDATE phpbb_users
SET user_nthpost = (
SELECT post_time FROM phpbb_posts
WHERE phpbb_users.user_id = phpbb_posts.poster_id
ORDER BY post_time ASC
LIMIT $n,1
)

ANay ideas to how I'd do this on MySQL (which doesn't support
subqueries)?

I could do something like...

for each $user_id and for some $n, set $user_nthpost equal to the
result of the following:

SELECT post_time FROM phpbb_posts
WHERE phpbb_posts.poster_id = $user_id
ORDER BY post_time ASC
LIMIT $n,1

then...

UPDATE phpbb_users SET user_nth_post = $user_nthpost WHERE user_id =
$user_id

Unfortunately, if there are a lot of $user_id's, this could be quite
slow. It'd take 2*(the number of users) queries to finish.

Is there a way I can do it, instead, with maybe, I dunno... 1 query,
or 2, or 3, or some other small (and fixed) number?

Any ideas would be appreciated - thanks!


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.