Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

mysql, left join, group by

Empfohlene Antworten

Veröffentlicht

hu,

möglich das ich unter Gedächnisschwund leide ^^, habe hier ein SQL-Statement das ich nicht ganz nachvollziehen kann.

tabelle2 enthält geloggte Statusmeldungen über Datensätze in Tabelle 1

Tabelle1: - news

newsid (Primary Key)

Titel

Text

Tabelle 2: - logs

logid (Primary Key)

newsid (foreign key)

Status (active, old, important)

Userid (wer etwas geändert hat)

timestamp (wann geändert wurde)

nun das Statement:

select news.newsid, news.titel, news.text, logs.status, logs.userid, logs.timestamp from news left join logs on logs.newsid = news.newsid group by newsid order by newsid

im prinzip ginge es auch ohne left join, kommt etwa aufs gleiche hinaus.

Bei dem Statement hätte ich einen Fehler erwartet, da es pro News-Element mehrere Logeinträge mit verschiedenen Stati gibt, aber nur die ID gegroupt wird. Oder wie wird nun bestimmt welcher Datensatz für das Feld logs.Status benutzt wird, wenn am Ende je News nur 1 Ergebnis-Datensatz herauskommt ?

(Beispielsituation, hängt mich nicht an der logik der daten auf ^^)

danke

ich habe

MySQL AB :: MySQL 5.1 Referenzhandbuch :: 12.11.3 GROUP BY mit versteckten Feldern

gefunden

worin steht:

Verwenden Sie diese Funktion nicht, wenn die Spalten, die Sie im GROUP BY-Anteil weglassen, in der Gruppe nicht eindeutig sind! Sie erhalten ansonsten nicht vorhersehbare Ergebnisse.

soweit ist doch logs.status nicht eindeutig, oder ?

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.