MySQL 中的连接查询
我有两个表:members 和 renews
这两个表有一个名为 memberid 的字段,它将两个数据表链接在一起。我正在尝试构建一个查询,该查询将从成员表中提取名字和姓氏,以获取续订表中保存的数据。我尝试使用下面的查询,该查询基于我查找的一些示例。
SELECT members.memberfirst, members.membersurname, members.memberid, renewals.account_name, renewals.memberid
FROM members, renewals
WHERE renewals.memberid=members.memberid
尝试在 phpMyAdmin 中运行此命令时出现错误:
#1267 - Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
I have two tables: members and renewals
The two tables have a field called memberid which links the two data tables together. I am trying to construct a query which will extract the firstname and surname from the members table for the data that is being held in the renewals table. I have tried using the query below which is based on some examples I've looked up.
SELECT members.memberfirst, members.membersurname, members.memberid, renewals.account_name, renewals.memberid
FROM members, renewals
WHERE renewals.memberid=members.memberid
The error I get when trying to run this in phpMyAdmin:
#1267 - Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
INNER JOIN
。看一下这里: http://www.postgresql.org /docs/8.1/interactive/queries-table-expressions.html即使是针对 PostgreSQL,查询对于 MySQL 来说也是一样的,而且示例也非常好。
或者您可以使用
USING (memberid)
而不是ON Members.memberid =renewals.memberid
You should use
INNER JOIN
. Take a look here: http://www.postgresql.org/docs/8.1/interactive/queries-table-expressions.htmlEven if it's for PostgreSQL, the queries are the same for MySQL and the examples are really good.
or you can use
USING (memberid)
instead ofON members.memberid = renewals.memberid
如果您想在单列中显示会员姓名,请稍加修改
A slight modification if you wanted to display the member's name in a single column