[BraLUG] SQL-Problem

Robert Schulze rob at net-pr.de
Fr Apr 27 13:11:16 CEST 2007


Hi,

ich habe ein Problem mit einer SQL-Abfrage.

Ich will aus drei Tabellen beliebige 4 Datensätze extrahieren, die in einer
besonderen Spalte unterschiedlich sind. Es geht dabei um die Tabellen
mrp_Destination, mrp_Housing und mrp_Housing_Price.

mrp_Destination fasst u.a. ein Feld 'Lage'.
mrp_Housing beinhaltet Unterkünfte, jede solche bezieht sich auf 1 Datensatz
in mrp_Destination.
mrp_Housing_Prices beinhaltet für jeden Datensatz in mrp_Housing einige
Preise.

Ich will nun genau 4 Datensätze rausholen, nämlich zu jeder Lage (1..4)
genau eine Unterkunft, die aber zufällig sein soll. Mit folgendem Query
bekomme ich aber immer genau die selben Objekte, was kann ich dagegen tun?

Vielen Dank schonmal,
Rob


SELECT
        mrp_Housing.ID AS ID,
        mrp_Housing.Ausstattung_Bild_1 AS Ausstattung_Bild_1,
        mrp_Housing.Typ AS Typ,
        mrp_Destination.Lage AS Lage,
        mrp_Destination.Name AS Destination,
        mrp_Housing_Price.Price AS Preis
FROM
        mrp_Housing,
        mrp_Destination,
        mrp_Housing_Price

WHERE
        (mrp_Housing.Destination=mrp_Destination.ID) AND
        (mrp_Housing.ID=mrp_Housing_Price.Housing)

GROUP BY mrp_Destination.Lage;




Mehr Informationen über die Mailingliste Bralug