简体   繁体   English

where 子句中的未知列 — Mysql

[英]Unknown column in where clause — Mysql

Well i am trying a statement like this..好吧,我正在尝试这样的声明..

UPDATE pubs SET pubs.id=parentid.id WHERE parentid.title=pubs.title

well id is the primary key of parentid..井id是parentid的主键..

the error thrown up is抛出的错误是

Error:Unknown column 'parentid.title' in 'where clause'

Help appreciated帮助表示赞赏

I'm not sure what you're looking for.我不确定你在找什么。 The key is that you need to specify the parent-child join in your SQL.关键是你需要在你的SQL中指定父子join。

If your parents are already setup in a self-referential join, use the following:如果您的父母已经设置了自引用连接,请使用以下内容:

UPDATE p
SET p.id=parentid.id
FROM pubs p
JOIN pubs parent
ON parent.id = p.parentid
WHERE parent.title=p.title

If you're looking to define parent-child relationships based on the titles, use this:如果您希望根据标题定义父子关系,请使用以下命令:

UPDATE p
SET p.id=parentid.id
FROM pubs p
JOIN pubs parent
ON parent.title=p.title

The problem in your statement is you have used parentid table directly in the where clause.您语句中的问题是您在 where 子句中直接使用了 parentid 表。 First of all, all the tables you are going to use must be in the 'FROM' clause.首先,您要使用的所有表都必须在“FROM”子句中。 Once a table is in 'FROM' clause, you can use it in 'WHERE'.一旦表在“FROM”子句中,您就可以在“WHERE”中使用它。

As you are expecting a relation between the tables in the where clause as parentid.title=pubs.title, you can use this relation for JOINING the both tables.由于您期望 where 子句中的表之间的关系为 parentid.title=pubs.title,您可以使用此关系来连接两个表。

So, instead of WHERE, you can JOIN the both tables as 'pubs JOIN parent ON pubs.title = parentid.title'因此,您可以将两个表作为“pubs JOIN parent ON pubs.title = parentid.title”而不是 WHERE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM