mysql - 连接表 id

标签 mysql

你好

我有3张 table

cc_host_uploads contains
upload_id       file_id

cc_host_files contains
file_id         user_id

cc_host_users contains
user_id

到目前为止,3 个表之间有一个链接(id),我想要的是两个表之间的链接。

我希望 cc_host_uploads 表将 user_id 插入 file_id...所以我需要以某种方式加入它们。

有人可以启发我吗?谢谢!

最佳答案

我想这就是你的意思?通过文件获取上传的用户?

SELECT upload.*, user.id from cc_hosts_uploads upload
INNER JOIN cc_hosts_files files on upload.id = files.upload_id
INNER JOIN cc_host_users user on user.id = files.user_id

关于mysql - 连接表 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13101971/

相关文章:

PHPMyAdmin 说 : The used command is not allowed with this MySQL version

mysql - MYSQL 中的 Friendfeed 无模式数据

mysql - 选择彼此相差超过一秒的行MYSQL

php - PDO "Integrity constraint violation - Duplicate entry",但表中没有重复项

MySql 查询未返回正确的数据

mysql - 选择一个mysql表的所有内容,并回显对应类别的列表

mysql - 从 mysql 的校验和表中选择并仅返回校验和(而不是表)

php - 使用 UNION 查询在 while 语句中获取总数

php - 如何将两个或多个mysql数组合并为一个

mysql - 搜索原始日期 - MYSQL