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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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! |