Question

I got the following query at MySQL Workbench

SELECT products_name,
    products_weight
FROM zen_products zp
JOIN zen_products_description pd ON zp.products_id = pd.products_id

Becuase the products_id are the same in both tables and these are the primary keys, how do I go about then to edit both tables from one query output. As it states at the moment: Read Only.

Was it helpful?

Solution

No workbench user, but in general in databases there's no "edit" command. It's a term workbench seems to have invented and it can mean two things:

  1. Editing the table/database structure. In SQL this is done via the ALTER TABLE ... command.

  2. Editing the data in one or more tables. In SQL this is done via the three commands UPDATE, DELETE and INSERT.

Editing a table/database structure is done to only one table at a time. There's no joining allowed when doing this. That's why there's the "read only" note, if workbench means this with "editing". I'm assuming you mean to edit the data, especially updating it. An example would be

UPDATE zen_products zp
JOIN zen_products_description pd ON zp.products_id = pd.products_id
SET
zp.products_name = pd.another_column,
zp.products_weight = zp.products_weight + 1;

Note, that there are no restrictions on primary keys or anything, to update a table. You can join on any field and still update it. Given of course, you have the right to do so. Please execute this query:

SHOW GRANTS FOR username@host;

to see if you have the rights to update the table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top