Err 1054 - 'where子句'mysql中的未知列'列'

时间:2014-01-03 18:52:27

标签: mysql

我在MySQL中遇到了问题。这是我的代码:

UPDATE ad_copy, (
    SELECT CONCAT_WS(" - ", ad_copy.title, stitle.ttitle) AS `p` 
    from ad_copy, stitle 
    where ad_copy.category = stitle.subcat 
    ORDER BY RAND()) `p` 
set `title` = `p` 
where ad_copy.category = stitle.subcat

我无法理解问题所在。在此先感谢您的帮助

1 个答案:

答案 0 :(得分:0)

尝试使用加入更新,无法识别子查询(SELECT CONCAT_WS ..) as p的自定义列

UPDATE 
ad_copy a
JOIN stitle  s ON (a.category = s.subcat)
SET a.`title` = CONCAT_WS( " - ",a.title,s.ttitle) 

修改

UPDATE 
ad_copy a
JOIN stitle  s ON (a.category = s.subcat)
SET a.`title` = CONCAT_WS( " - ",a.title, (SELECT ttitle FROM stitle WHERE subcat =a.category ORDER BY RAND() LIMIT 1 ))