sql >> Base de Datos >  >> RDS >> Mysql

Recuperación de etiquetas según el ID de la publicación

Unión implícita:

SELECT title, clean_title, body, published, name, slug
FROM posts, posts_tags, tags
WHERE posts.p_id=posts_tags.p_id AND posts_tags.t_id=tags.t_id
ORDER BY published DESC

Unión explícita:

SELECT title, clean_title, body, published, name, slug
FROM posts
LEFT JOIN posts_tags ON posts.p_id=posts_tags.p_id
LEFT JOIN tags ON posts_tags.t_id=tags.t_id
ORDER BY published DESC

Es refrescante ver un esquema de base de datos correcto y normalizado por una vez.