Read-only after inner join (MySQL)

2019-09-02 05:18发布

问题:

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