我有两个表,dma_projects 和 projectsteps:
dma_projects 有以下字段: projectID projectName projectInstructions
CREATE TABLE IF NOT EXISTS `dma_projects` (
`projectID` int(11) NOT NULL DEFAULT '0',
`projectName` varchar(100) DEFAULT NULL,
`projectDescription` text,
`projectImage` varchar(255) DEFAULT NULL,
`projectThumb` varchar(255) DEFAULT NULL,
`projectCategory` varchar(50) DEFAULT NULL,
`projectTheme` varchar(50) DEFAULT NULL,
`projectInstructions` text,
`projectAuthorID` int(11) DEFAULT NULL,
`projectViews` int(11) DEFAULT NULL,
`projectDifficulty` varchar(20) DEFAULT NULL,
`projectTimeNeeded` varchar(40) DEFAULT NULL,
`projectDateAdded` int(11) DEFAULT NULL,
`projectStatus` varchar(20) DEFAULT NULL,
`projectVisible` varchar(1) DEFAULT NULL,
PRIMARY KEY (`projectID`),
KEY `user_id` (`projectAuthorID`),
KEY `date` (`projectDateAdded`),
FULLTEXT KEY `image` (`projectImage`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
projectsteps 有: stepID stepno stepdesc project_id
CREATE TABLE IF NOT EXISTS `projectsteps` (
`projectStep_id` int(11) NOT NULL AUTO_INCREMENT,
`stepno` int(11) DEFAULT '0',
`stepdesc` text CHARACTER SET utf8 COLLATE utf8_bin,
`project_id` int(11) NOT NULL,
PRIMARY KEY (`projectStep_id`)
)
我想用在 projectsteps 表中找到的具有相同 projectID 的任何行的值更新 dma_projects.projectInstructions。
IE
dma_projects 中的 projectID 1 在 projectsteps 中有 5 条记录,这 5 条记录的 stepdesc 应连接(用 a 分隔
),然后更新到 dma_projects 表的 projectInstructions 字段。
我正在为如何编写查询而挠头。这是我到目前为止的位置,但我无法让它工作。它说的错误是:
Unknown column 'projectsteps.stepno' in 'field list'
这是查询:
UPDATE `dma_projects` t1
SET t1.`projectInstructions` =
(
SELECT
`projectsteps`.`stepno`,
group_concat(`projectsteps`.`stepdesc` separator '<br/>')
FROM `projectsteps`
AS somevar
INNER JOIN `projectsteps` t2
ON t1.projectID=t2.project_id
ORDER BY t2.stepno ASC
)