帮忙看个SQL问题

php中文网
发布: 2016-06-23 13:44:53
原创
857人浏览过

SELECT ornamentation_images.ismark ismark,ornamentation_images.width width,ornamentation_images.height height,users.nickname name,ornamentations.id id,ornamentations.image_name image_name,ornamentations.image_url image_url,ornamentations.add_author add_author,ornamentations.browse_real_cnt browse_real_cnt,ornamentations.comnum comnum,users.head head,users.comnum unreadFROM `ornamentation_images` LEFT JOIN users on ornamentation_images.add_author=users.id LEFT JOIN ornamentations on ornamentation_images.ornamentation_id=ornamentations.id WHERE ( ornamentations.enable = 0 ) AND ( ornamentations.checkstatus = 2 )  ORDER BY ornamentations.id desc LIMIT 0,5
登录后复制

能查出来结果,只是没有查出来users表里的数据,问题出在哪?

AI帮个忙
AI帮个忙

多功能AI小工具,帮你快速生成周报、日报、邮、简历等

AI帮个忙 55
查看详情 AI帮个忙

回复讨论(解决方案)

表结构在哪呢

可能是left join 的问题
left join是以左表的记录为基础的,ornamentation_images可以看成左表,users可以看成右表,left join是以左表为准的.
换句话说,左表的记录将会全部表示出来,而右表只会显示符合搜索条件的记录,右表记录不足的地方均为NULL.

楼主可以查看一下,是否这个原因呢

表结构在哪呢


users表在ornamentation_images上,ornamentations也在ornamentation_images上

可能是left join 的问题
left join是以左表的记录为基础的,ornamentation_images可以看成左表,users可以看成右表,left join是以左表为准的.
换句话说,左表的记录将会全部表示出来,而右表只会显示符合搜索条件的记录,右表记录不足的地方均为NULL.

楼主可以查看一下,是否这个原因呢


不是,换了right和inner都不行

可能是left join 的问题
left join是以左表的记录为基础的,ornamentation_images可以看成左表,users可以看成右表,left join是以左表为准的.
换句话说,左表的记录将会全部表示出来,而右表只会显示符合搜索条件的记录,右表记录不足的地方均为NULL.

楼主可以查看一下,是否这个原因呢


找到问题了,是where的问题,把where条件去掉就有了。但是必须要带where呀,该怎么写呢?

那应该是表中没有符合这个where条件的记录

那应该是表中没有符合这个where条件的记录


恩,的确是数据库问题,sql没问题,结贴

一个可能是你关联user表错误另一个就是在你当前where条件下user表里面没有数据满足

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号