gpt4 book ai didi

MySQL 查询 : join these tables in order to get all tag_names used by any given `user_id` on all of his images?

转载 作者:行者123 更新时间:2023-12-01 00:06:52 25 4
gpt4 key购买 nike

考虑以下表结构:

users (user_id, ...)
images (image_id, user_id, ...)
tag_links (tag_id, image_id)
tags_names (tag_id, tag_name)

假设任何给定的 user_idimages 表中有多个图像,并且一个图像有多个标签存储在 tag_links 中。

我怎样才能加入这些表,以便获得任何给定 user_id 在他的所有图像上使用的所有 tag_names?这些类型的查询(连接多个表)是否缓慢且不推荐,或者这样做是否很常见?

最佳答案

加入很常见,这是应该的方式。

SELECT tn.tag_name
FROM tags_names AS tn
INNER JOIN tag_links AS tl ON tn.tag_id=tl.tag_id
INNER JOIN images AS i ON tl.image_id=i.image_id
WHERE i.user_id=YOURUSERID

但只有当标签可以有多个名称时,如果不在 tag_links 上使用列 name,您的表设计才有意义。

关于MySQL 查询 : join these tables in order to get all tag_names used by any given `user_id` on all of his images?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6829076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com