Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Zufällige Select-Unterabfrage in MySQL bei Verwendung von GroupBy

Komisch, ich habe es endlich zum Laufen gebracht, indem ich die gewünschten Spalten in der Unterabfrage in einem group by hinzugefügt habe , so :

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

Ich habe nicht die gesamte Anfrage getestet, aber den Trick an einer meiner DBs getestet und es funktioniert.