Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Randomizando a subconsulta Select no MySQL ao usar GroupBy


Engraçado, eu finalmente fiz funcionar adicionando as colunas que queríamos na subconsulta em um group by , assim :
SELECT 
    country.guid,
    country.Name AS 'country name',
    country.Area_id,
    country_cities.guid,
    country_cities.name AS 'city name',
    country_streets.guid,
    country_streets.name AS 'country streets',
    memebers.name.guid,
    memebers.name AS 'street members'
FROM
    country
        JOIN
    (SELECT 
        RAND() as seed, country_id, guid, name
    FROM
        street_members GROUP BY seed, name, guid,country_id ORDER BY seed) memebers ON memebers.country_id = country.id
        JOIN
    country_cities ON country_cities.country_id = country.id
        JOIN
    country_streets ON country_streets.city_id = country_cities.id
GROUP BY country.guid , country_cities.guid , country_streets.guid
ORDER BY RAND()
LIMIT 0 , 100

Não testei todo o pedido, mas testei o truque em um dos meus DB e funcionou.