内连接 MYSQL 查询不起作用 [英] Inner join MYSQL query not working

查看:88
本文介绍了内连接 MYSQL 查询不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含三个表的表结构:profiles、profile_subrubriek 和 rubrieken.我使用以下查询查询数据:

I have a table structure with three tables: profiles, profile_subrubriek and rubrieken. I query the data with the following query:

SELECT profiles.hoofdrubriek, profiles.plaats
, profiles.bedrijfsnaam, profiles.gemeente, profiles.bedrijfsslogan
, profiles.straatnaam, profiles.huisnummer, profiles.postcode
, profiles.telefoonnummer, profiles.fax, profiles.email
, profiles.website, profiles.bedrijfslogo 

FROM profiles INNER JOIN profile_subrubriek ON profiles.ID=profile_subrubriek.profile_id 
INNER JOIN rubrieken ON profile_subrubriek.subrubriek_id=rubrieken.ID  

where (
rubrieken.rubriek = 'Aannemersbedrijven' 
OR 
profiles.hoofdrubriek = 'Aannemersbedrijven') 
AND profiles.gemeente = 'Dongen'

结果,0 行.那是不正确的.如果我取出 Inner Join 并且只在 WHERE clausule 中加入 'hoofdrubriek' 列,我会得到大约 25 行,这是正确的.所以这个查询(上面的修改版本)确实有效:

The result, 0 rows. That is not correct. If I take out the Inner Join and only incorporate the 'hoofdrubriek' column in the WHERE clausule I get about 25 rows as a result, that is correct. So this query (modified version of the above) does actually work:

SELECT profiles.hoofdrubriek, profiles.plaats, profiles.bedrijfsnaam
, profiles.gemeente, profiles.bedrijfsslogan, profiles.straatnaam
, profiles.huisnummer, profiles.postcode, profiles.telefoonnummer
, profiles.fax, profiles.email, profiles.website, profiles.bedrijfslogo 

FROM profiles where (profiles.hoofdrubriek = 'Aannemersbedrijven') 
AND profiles.gemeente = 'Dongen'

我做错了什么?

谢谢!

推荐答案

可能连接的表不包含引用的值.尝试 LEFT JOIN 而不是 INNER JOIN.

Probably the joined tables don't contain referenced values. Try LEFT JOIN instead of INNER JOIN.

这篇关于内连接 MYSQL 查询不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆