mysql - 加入五张 table

标签 mysql join

<分区>

我试图通过连接五个表来创建图像的过滤器输出。由于我的 where 语句,我需要连接五个表。我的 sql 如下:

SELECT `files`.`id` AS `id`,
    `files`.`name` AS `name`,
    `files`.`size` AS `size`, 
    `files`.`type` AS `type`, 
    `files`.`url` AS `url`, 
    `files`.`title` AS `title`, 
    `files`.`description` AS `description`, 
    `files`.`category` AS `category` 
FROM `files` 
INNER JOIN `folders` 
    ON `files`.`category` = `folders`.`id` 
INNER JOIN `access` 
    ON `access`.`folder_id` = `folders`.`id` 
INNER JOIN `tags_files` 
    ON `tags_files`.`file_id` = `file`.`id` 
INNER JOIN `tags` 
    ON `tags`.`id` = `tags_files`.`tag_id` 
WHERE ( `access`.`user_id` = 11 ) 
    AND ( `files`.`type` = 'application/x-photoshop' 
         OR `files`.`type` = 'image/jpeg' 
         OR `files`.`type` = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' OR type = 'application/download' 
         OR `files`.`type` = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' 
         OR type = 'application/msword' 
         OR `files`.`type` = 'application/postscript' 
         OR `files`.`type` = 'image/png' 
         OR `files`.`type` = 'application/pdf' 
         OR `files`.`type` = 'image/tiff' 
         OR `files`.`type` = 'image/gif' 
         OR `files`.`type` = 'application/vnd.openxmlformats-officedocument.presentationml.presentation' 
         OR `files`.`type` = 'application/octet-stream' 
         OR `files`.`type` = 'application/zip' 
         OR `files`.`type` = 'text/plain' OR `files`.`type` = 'text/rtf' ) 
    AND ( `tags`.`name` = 'apple' )

我开始时只有三个表:

files, folders, access

一切顺利,但添加了最后两个

tag, tags_files

我收到以下错误:

1054 - Unknown column 'file.id' in 'on clause'

这很奇怪,因为那是我开始时使用的表格...感谢您的帮助!

最佳答案

您的请求中没有 file.idfiles.id 存在,我不确定,因为我没有表结构。 . .

关于mysql - 加入五张 table ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25260403/

相关文章:

php - 如何从列略有不同的两个表中选择行?我怎样才能抵消它们?

sql - 如何通过插入序列 DESC 对数据进行排序?

php - 将许多 MySQL 查询与逻辑合并到数据文件中

mysql - 将新的行集添加到现有查询的结果集中

mysql - mySQL 的 Join 问题 - 可以做我想做的事吗?

php - 比较并显示不匹配的数据

PHP 事务在我的 wamp 上不起作用

javascript - 如何使用 LoopBack 3 增加一些数据而不损害一致性?

mysql - 我的sql搜索语法实现

r - 临时连接周围的r.data.table函数包装器(链中聚合)