Support the ongoing development of Laravel.io →
posted 9 years ago
Database
Last updated 1 year ago.
0
SELECT * /* Consider specifying columns */
FROM eanprod.activepropertylist
(
    SELECT *  /* Consider specifying columns */
    FROM eanprod.activepropertylist
    WHERE StateProvince IN("NW","WA","SA","NT","VC")
)
ORDER BY RAND() 
LIMIT 4

EDIT: Just realized you said one in each state, can this not be done in PHP for some reason?

IMHO it's faster to do the random select in PHP

Last updated 9 years ago.
0

Here ya go

/* Consider specifying columns in selects */
SELECT * FROM(
    SELECT *
    FROM eanprod.activepropertylist
    WHERE StateProvince IN("NW","WA","SA","NT","VC")
    ORDER BY RAND()
) AS shuffled
GROUP BY StateProvince;
0

Thanks That words

But I would like to get 4 hotels from each state (36 total) in this query though.

It only get 1 hotel from each of the states

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ottz0 ottz0 Joined 15 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.