sql - MySql random category limited select -


I am trying to create a query that will select one item for the first category, two items for the other And two item categories for the third, just one item for others

The problem is that there should be a query. I think this is possible, but I can not understand it

this:

  SELECT * (SELECT i. * Items From where i.categoryid = 1 LIMIT 1), (SELECT i. * Items from I.categoryid = 2 LIMIT 2), (SELECT i. * Items where i.categoryid = 3 LIMIT 2)  < / Pre> 

... will select one item for the first category, two items for the second and 2 items for the third category. I use UNION ALL more than because it is faster because it does not remove duplicates, without knowing more about the data model (included tables) It is difficult to say what would be best.


Comments

Popular posts from this blog

MySql variables and php -

c# - How can I find out if there are windows above a control? -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -