2

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.

Newbie
  • 341
  • 1
  • 7
  • 17
  • 1
    Show your attempted update. – Barmar Dec 29 '14 at 08:58
  • 1
    What do you want to update on customers table? – Saharsh Shah Dec 29 '14 at 09:01
  • Since I am using MySQL workbench, I wanted to join the tables first, and update the output table by double-clicking the box I wanted to change. Thank you. – Newbie Dec 29 '14 at 09:07
  • It seems to be a gui user question. Rows in Mysql workbench do become readonly, when there is a join, because the application does not know, how to build a query to update the fields you want to change. You need to reference the specific rows by ids. – newtover Dec 29 '14 at 09:16
  • The FAQ that explains "Read Only" behavior: http://dev.mysql.com/doc/workbench/en/workbench-faq.html#qandaitem-A-3-1 -- basically, you need a PK in the results. – Philip Olson Dec 31 '14 at 17:30
  • Thank you, Philip, that partly explains the problem. – Newbie Jan 06 '15 at 09:11

3 Answers3

3

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.

Newbie
  • 341
  • 1
  • 7
  • 17
0

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.

Michael Coleman
  • 3,288
  • 3
  • 19
  • 18
0

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

Community
  • 1
  • 1
belostoky
  • 934
  • 2
  • 11
  • 22