Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 09-24-2007, 09:50 PM MySQL sorting issue
skyblue's Avatar
Super Talker

Posts: 101
Trades: 0
I have the problem with sorting rows by different criteria. I have games table and among others, there are rate and category columns. What i want is to select 4 most popular games from all categories, i mean 4 most popular action games, 4 strategies etc. I hope i described my problem well. SQL experts, help me please!

Thanks in advance,
Milan
skyblue is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-25-2007, 05:19 PM Re: MySQL sorting issue
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
I don't know what your table looks like so I can't give you an exact query but it would be something like:

SELECT * FROM `games` WHERE `genre`='action' ORDER BY `popularity` DESC LIMIT 4;

Just make a seperate query for each genre.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-25-2007, 06:12 PM Re: MySQL sorting issue
skyblue's Avatar
Super Talker

Posts: 101
Trades: 0
Ok...but i was wondering if there is any way to do this in only one query. I would like to save some server resources.

Thank you anyway.
skyblue is offline
Reply With Quote
View Public Profile
 
Old 09-25-2007, 07:54 PM Re: MySQL sorting issue
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Well, I'm not even sure mysql could do it.
You could write 1 big query for each genres, and use an UNION to link ever results together, supposedly that mysql can use an union joint.
I Don't know, I'm more used to oracle/postgres...

But seriously, php would let you go much faster to your point, and the resources used by that kind of query is like the amount of concentration you require to breath...
Almost null...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-26-2007, 12:51 PM Re: MySQL sorting issue
skyblue's Avatar
Super Talker

Posts: 101
Trades: 0
Ok, then i suppose i have to do one query for every category.
skyblue is offline
Reply With Quote
View Public Profile
 
Old 09-26-2007, 01:35 PM Re: MySQL sorting issue
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Yeah thats probably the best approach. Making multiple queries, like those, won't eat up much execution time so I wouldn't worry about that.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to MySQL sorting issue
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30358 seconds with 12 queries