Ok, j'ai trouvé la situation. 3 tables, étiquettes, livres et la table d'intersection *. Comment faites-vous face à cela à nouveau?Tags utilisant JOINs
tags
-id int
-name varchar
books
-id int
-name varchar
taggings
-tagId_fk int
-bookId_fk int
Données d'échantillons
tags id name 1 good 2 really good 3 bad 4 long 5 exciting books id name 1 Pumpkin Man 2 O-castic Bastard taggings bookId_fk tagId_fk 1 1 1 4 2 4 2 5
Voici Pumpkin Man a été identifiée comme good
et long
tandis que O-Castic Bastard a été identifiée comme long
et exciting
.
Je veux écrire une seule requête qui extrait:
books.id books.name taggings.tagId_fk as tags.name (know what I mean?) 1 Pumpkin Man good 1 Pumpkin Man long 2 O-castic Bastard long 2 O-castic Bastard exciting
Pas exactement ce que je veux
SELECT DISTINCT taggings.bookId_fk, tags.name FROM tags INNER JOIN taggings ON taggings.tagId_fk=tags.tagId ORDER BY taggings.bookId_fk;
La question que j'ai vraiment est, est-il même possible d'afficher le résultat ci-dessus MySQL sans:
- Briser dans plus d'une requête,
- Utilisation d'une sous-requête?
* PS Je sais que some people don't use an intersection table