Author Topic: Seeking advice: MySQL query  (Read 420 times)

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Seeking advice: MySQL query
« on: December 03, 2014, 09:01:04 pm »


               

Hi,


 


Working on a db driven loot system, I need to build a fancy query and I'm not sure about the best approach to use. The system itself is rather simple, randomizing over weighted records of category tables with :


 


SELECT resref FROM table ORDER BY rand()*rarity ASC LIMIT 1


 


I know, using ORDER BY RAND() is unadvised, but my tables hold 200-500 records, hopefully the speed will not be affected too much, yet if you know a better approach I'm all ears of course.


 


So, the problem is, I have one table(categories) holding all the available loot categories, each one being indexed by a bitwise value(fortunately I have fewer than 32 categories). Each category on this table is weighted and should refer to another table holding the items of the category. So I need the query to randomize on the categories table, then randomize on the (items) table returned by the first operation, yielding a random item resref. 2 queries would work, but can a single, faster query do it?


 


Thanks for your time


Kato 



               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Seeking advice: MySQL query
« Reply #1 on: December 04, 2014, 08:14:48 pm »


               

Never mind, found the solution, thanks anyway