2

这是我无法运行的 SQL 语句:

SELECT fm . * , mp.first_name, mp.last_name, mp.image, mp.member_id
FROM featured_members AS fm
JOIN member_profiles AS mp WHERE fm.member_id = mp.member_id
AND fm.member_type_id =6
AND fm.site_id =1

当我运行它时,它给了我#1054 - Unknown column 'fm.site_id' in 'on clause'错误

是否存在语法问题,因为 fm 表确实有该 site_id 列,但我不知道为什么 SQL 没有获取它?

我的表结构 featured_members是这样的:

1 sr_no     
2 member_id     
3 member_type_id 
4 site_id   

member_profiles结构是:

1 member_profile_id 
2 member_id     
3 first_name    
4 middle_name   
5 last_name     
6 gender
7 image
4

5 回答 5

2

你做错了:对于 JOIN,必须使用 ON 子句,除非它是交叉连接。

SELECT fm . * , mp.first_name, mp.last_name, mp.image, mp.member_id
FROM   featured_members AS fm
JOIN   member_profiles  AS mp ON ( fm.member_id = mp.member_id )
WHERE fm.member_type_id =6
AND fm.site_id =1
于 2013-01-18T14:16:42.393 回答
1

测试这个:

SELECT fm.*, mp.first_name, mp.last_name, mp.image, mp.member_id
FROM featured_members AS fm
LEFT JOIN member_profiles AS mp ON fm.member_id = mp.member_id
WHERE fm.member_type_id =6 AND fm.site_id =1
于 2013-01-18T14:17:34.983 回答
1

您的查询中缺少“on”子句,而 MySQL 需要它。因此,在我看来,Moddom 提供的解决方案是正确的答案。

请参阅http://dev.mysql.com/doc/refman/5.0/en/join.htmlhttp://bugs.mysql.com/bug.php?id=13551

于 2013-01-18T14:38:13.887 回答
1

试试这个...

SELECT fm . * , mp.first_name, mp.last_name, mp.image, mp.member_id
FROM featured_members AS fm, member_profiles AS mp
WHERE fm.member_id = mp.member_id
AND fm.member_type_id =6
AND fm.site_id =1

您的语句中的 JOIN 子句需要相应的 ON ,这是导致错误的原因

于 2013-01-18T14:41:15.240 回答
0

试试这个:-

SELECT fm . * , mp.first_name, mp.last_name, mp.image, mp.member_id <br>
FROM featured_members fm , member_profiles mp <br>
where fm.member_id = mp.member_id <br>
AND fm.member_type_id =6 <br>
AND fm.site_id =1
于 2014-12-23T10:01:02.677 回答