Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > select rows where id in (select...limit x) limit z Not Allowed?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-19-07, 00:41
djuritz djuritz is offline
Registered User
 
Join Date: Sep 2005
Posts: 33
select rows where id in (select...limit x) limit z Not Allowed?

Hi.

I have a table with videos (id, title, views)
I want to display the most viewed videos.
I don't want to show always the same top ten por example.
The solution is to select the top 30 and then get 5 random from them.

MySQL version is 5.0.45 (lastest)

The query is:
SELECT * FROM video WHERE id IN (
SELECT id
FROM video v
ORDER BY visitas
LIMIT 30) x
ORDER BY rand()
LIMIT 10

(alias X and V are mandatory for MySQL)

The problem is I get this error: #1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

Is there any solution?
The only way is by using 2 queries and PHP. Isn't it?
The first one to get top 30 (just id's) and then top 10 where id IN (id´s from first query).

Thanks a lot!
Reply With Quote
  #2 (permalink)  
Old 10-19-07, 02:40
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
my advice: return the top 30, then use php to pick 10 at random

keeps the query simple

__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On