显示所有联系人组时,MySQL显示有限数量的联系人

时间:2013-09-21 14:12:29

标签: mysql

我有一个被称为联系人的地址簿。为了帮助组织联系我有团体(例如家人,朋友,工作)。我想说,每组显示4或10个联系人示例。这适用于列出所有组的组索引页面,但不打算每个组具有完整的联系人列表(仅适用于专用组页面)。

组表和列

email_groups

idid_username

通讯录表格和列

email_contacts

idid_groupid_username

我一直在努力解决这个问题,但c1的列名错误。

SELECT 
eg.id, 
eg.name, 
(SELECT c1.name FROM email_contacts AS c1 WHERE id_user='1' LIMIT 0,1) AS contact_1, 
(SELECT c2.name FROM email_contacts AS c1 WHERE id_user='1' LIMIT 1,1) AS contact_2, 
(SELECT c3.name FROM email_contacts AS c3 WHERE id_user='1' LIMIT 2,1) AS contact_3, 
(SELECT c4.name FROM email_contacts AS c4 WHERE id_user='1' LIMIT 3,1) AS contact_4 
FROM email_groups AS eg 
INNER JOIN email_contacts AS ec on ec.id=eg.id_group

1 个答案:

答案 0 :(得分:0)

您已在子查询中提供了两次别名C1,我猜第二个子查询将为C2,您尝试选择c2.name,但您提供的别名为{{ 1}} SELECT c2.name FROM email_contacts AS c1

c1