![]() |
Datenbank: MySQL • Version: 5 • Zugriff über: Zeos / MySQL Connector
SQL Tags mit und Verknüpfen
Hi,
ich suche eine passende SQL Abfrage. Ich habe 3 Tabellen(songs: Songdaten Title, Artist; tags: Schlagwörter; songtag: m:n Relation zwischen songs und tags;) Nun möchte ich alle Lieder ausgeben, die die Tags rock, pop und metal haben. Mein Problem liegt dabei in der UND Verknüpfung der Tags. Für die ODER Abfrage hab ich den SQL-Code:
SQL-Code:
Nur hab ich keine Idee für die UND Abfrage...
SELECT
s_artist, s_title FROM music__tagsong ts, music__songs s, music__tag t WHERE ts.ts_song = s.s_id AND ts.ts_tag = t.t_id AND t.t_name IN ('rock', 'pop', 'metal') ; Ciao, Björn |
Re: SQL Tags mit und Verknüpfen
Poste mal die vollständigen Metadaten der Tabellen
|
Re: SQL Tags mit und Verknüpfen
Ok, ich denke du meinst den Tabellencode:
SQL-Code:
--
-- Tabellenstruktur für Tabelle `music__songs` -- CREATE TABLE `music__songs` ( `s_id` int(11) NOT NULL auto_increment, `s_title` varchar(255) collate latin1_general_ci NOT NULL, `s_artist` varchar(255) collate latin1_general_ci NOT NULL, `s_album` varchar(255) collate latin1_general_ci NOT NULL, `s_rating` int(11) NOT NULL, `s_desc` text collate latin1_general_ci NOT NULL, `s_genre` varchar(255) collate latin1_general_ci NOT NULL, `s_addtime` int(11) NOT NULL, PRIMARY KEY (`s_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2370 ; -- -- Tabellenstruktur für Tabelle `music__tag` -- CREATE TABLE `music__tag` ( `t_id` int(11) NOT NULL auto_increment, `t_name` varchar(255) collate latin1_general_ci NOT NULL, `t_count` int(11) NOT NULL, PRIMARY KEY (`t_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1764 ; -- -- Tabellenstruktur für Tabelle `music__tagsong` -- CREATE TABLE `music__tagsong` ( `ts_id` int(11) NOT NULL auto_increment, `ts_tag` int(11) NOT NULL, `ts_song` int(11) NOT NULL, `ts_uid` int(11) NOT NULL default '0', PRIMARY KEY (`ts_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4674 ; |
Re: SQL Tags mit und Verknüpfen
Meinst du sowas hier?
SQL-Code:
Oder soll das selbe Lied wirklich 3 mal angezeigt werden?
SELECT
s_artist, s_title FROM music__tagsong ts, music__songs s, music__tag t WHERE ts.ts_song = s.s_id AND ts.ts_tag = t.t_id AND t.t_name IN ('rock', 'pop', 'metal') GROUP BY s_artist, s_title HAVING count(*) = 3 ; |
Re: SQL Tags mit und Verknüpfen
Genau das meine ich, die Abfrage funktionier wunderbar Danke :thumb:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:30 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz