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.

SQL Befehl für Alphabetische Sortierung obwohl Werte in unterschiedlichen Tabellen

Empfohlene Antworten

Veröffentlicht

Guten Abend

Ich hoffe ihr könnt mir helfen. Ich versuche zurzeit eine Alphabetische Sortierung von Namen mithilfe von SQL-Befehlen in PHP zu erstellen. Mein Problem dabei ist, die Werte sind in unterschiedlichen Tabellen.

Datenbankstruktur (nur relevante):

Tabelle: Band

Attribute: ID, Bandname

Tabelle: Alben

Attribute: ID, Albumname

Tabelle: Veröffentlichungen (Wichtig: 1 Album kann mehrere Bands haben [split-Alben])

Attribute: AlbumID, BandID

Tabelle: Sammlung

Attribute: UserID, AlbenID

So ich habe mir jetzt so einen SQL Befehl aufgestellt nur bin ich mir sicher das dieser nicht funktioniert. (Bisher noch ungetestet)

Versucht etwas übersichtlicher zu halten.


$ID = userID;

SELECT * FROM Band, Alben, Veröfentlichungen, Sammlung
WHERE Sammlung.UserID = $ID
AND Sammlung.AlbenID = Veröffentlichungen.AlbumID
AND Veröffentlichungen BandID = Band.ID
ORDER BY Band.Bandname DESC
[/PHP]

Mein Ziel:

Sortierung der Titel in der Sammlung nach Bandname, allerdings soll (das habe ich bisher noch nicht drin, da ich leider keine Ahnung habe wie das überhaupt gehen kann) erst die wo 2 oder mehr Bands bei einem Album mitmachen. Heißt:

Erst Split-Alben, dann normale Alben.

Wenn mir da irgendjemand helfen kann wäre ich dem echt dankbar, da im Moment meine Datenbank echt Sch**** aussieht. Die Werte stehen alle doppelt und dreifach drin. :(

Gruß

  • Autor

Bei dem SQL Befehl kommt leider nur 1 Ergebnis. Also

Band + Album

Das wars. Und dann auch noch das Album wo nur eine Band mitspielt.

Aktualisierter SQL-Befehlen


$ID = userID;

SELECT
*
FROM
Album,
Sammlung,
Band,
Veröffentlichung
WHERE
Sammlung.userid = $userID
AND
Sammlung.Albumid = Veröffentlichung.Albumid
AND
Veröffentlichung.Bandid = Band.`PRIMARY`
AND Veröffentlichung.Albumid = Album.`PRIMARY`
ORDER BY COUNT(Veröffentlichung.Albumid) DESC,
Band.name DESC
[/PHP]

Bearbeitet von Metaller

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.