Read-only after inner join (MySQL)

老子叫甜甜 提交于 2019-12-11 10:40:10

问题


In MySQL workbench (Mac OS), I wanted to join two tables so that I can update the second one. The code I put in was as follows

select f.company, f.remarks, c.pic
from feedback f, customers c
where f.col = c.col
order by f.company;

The output is a read only table, which prevented me from updating table "customers" based on the f.remarks column.

Your advice/suggestion is appreciated. Thank you.


回答1:


By hovering above the "Read Only" icon, I got the following message: "Statement must be a SELECT from a single table with a primary key for its results to be editable".

After some research based on the advice given by fellow coders, here are some points to note:

  1. In MySQL workbench, one cannot edit the results obtained from any JOINs because it's not from a single table;
  2. In using SELECT from a single table, the primary key must be included in order for the result to be editable.

Thank you to everyone who contributed to the question. I appreciate it.




回答2:


The problem is because, as you mentioned, SELECT only returns a "read only" result set.

So basically you cant use MySQL workbench to update a field in a read only result set that is returned when using a JOIN statement.




回答3:


from what i understand you want to update table "customers" based on a query.
maybe this post will help you:
update table based on subquery of table



来源:https://stackoverflow.com/questions/27685913/read-only-after-inner-join-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!