我试图从包含子字段的每个父行的子表中只获取一行,我一直在尝试使用 GRUOP BY 但没有成功:(这是我最初的 SELECT
SELECT pID, lastname
FROM parent
LEFT JOIN
(SELECT cID, pID, phone, company, title FROM child) as child
ON parent.pID = child.pID
这是表格结构
CREATE TABLE parent (
pID Counter(1,1) PRIMARY KEY,
firstname VarChar(24) DEFAULT '',
lastname VarChar(20) DEFAULT ''
);
CREATE TABLE child (
cID Counter(1,1) PRIMARY KEY,
pID int DEFAULT '0',
phone VarChar(16) DEFAULT '',
company VarChar(24) DEFAULT '',
title VarChar(24) DEFAULT '',
address TEXT
);