Unix Technical Forum

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

This is a discussion on converting a MySQL 4.1 subquery to something that'll work with MySQL 4.0 within the MySQL forums, part of the Database Server Software category; --> Say I have the following SQL query: UPDATE phpbb_users SET user_nthpost = ( SELECT post_time FROM phpbb_posts WHERE phpbb_users.user_id ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:58 AM
yawnmoth
 
Posts: n/a
Default converting a MySQL 4.1 subquery to something that'll work with MySQL 4.0

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!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:39 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com