small query problem
Posted: Tue Apr 29, 2008 9:36 am
Hi,
I know it's a generic data, but it will help simplify the question:
table with fields: ID (int, auto increment), name (varchar), price (int), company (int)
lets assume there are around 300 rows in this table.
company can be 1,2,3,4
is there a way to query the following:
shuffle all the data and return 4 results where 'company'=1 and 5 results where 'company'=2 and 3 results where 'company'=3 and 1 result where 'company'=4
I need a total of 4+5+3+1=13 rows, and to order them randomly (so it wont look like: company1,company1,company1,company1,company2,company2,company2...
any help is appreciated!
thanks!!!
I know it's a generic data, but it will help simplify the question:
table with fields: ID (int, auto increment), name (varchar), price (int), company (int)
lets assume there are around 300 rows in this table.
company can be 1,2,3,4
is there a way to query the following:
shuffle all the data and return 4 results where 'company'=1 and 5 results where 'company'=2 and 3 results where 'company'=3 and 1 result where 'company'=4
I need a total of 4+5+3+1=13 rows, and to order them randomly (so it wont look like: company1,company1,company1,company1,company2,company2,company2...
any help is appreciated!
thanks!!!