1

I need to update the column of some specific tables in my SQL database.

I've got a SELECT command, which selects ALL the right tables but i have no idea how i should combine that with UPDATE (I'm a complete noob).

SELECT
  c.id_customer AS id_customer,
  id_gender,
  firstname,
  lastname,
  c.email AS email,
  birthday,
  date_add,
  c.active AS active,
  c.*,
  a.id_group
FROM prstshp_customer_group a
LEFT JOIN prstshp_customer c
  ON (a.id_customer = c.id_customer)
WHERE 1
AND a.id_group = 4
AND c.deleted != 1
AND c.id_shop IN (1)
ORDER BY id_group ASC

I have to update the column called id_default_group in table prstshp_customer with the value "4", of specific entries, selected across the table prstshp_customer_group table.

1 Answer 1

1

use update join

update prstshp_customer
join
(
SELECT
  c.id_customer AS id_customer,
  id_gender,
  firstname,
  lastname,
  c.email AS email,
  birthday,
  date_add,
  c.active AS active,
  a.id_group
FROM prstshp_customer_group a
LEFT JOIN prstshp_customer c
  ON (a.id_customer = c.id_customer)
WHERE 1
AND a.id_group = 4
AND c.deleted != 1
AND c.id_shop IN (1)
)B on prstshp_customer.id_customer=B.id_customer
SET id_default_group=4
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for the fast response! I tried that and i get following errors: Static analysis: 3 errors were found during analysis. An expression was expected. (near "table" at position 7) Unrecognized keyword. (near "table" at position 7) Unexpected token. (near "prstshp_customer" at position 13)
Also tried to remove "table". Then i get "#1060 - Duplicate column name 'id_customer'"
I think its the c.* in SELECT is the reason
@tcadidot0, yes u r right - i didn't notice it - thank u
@MarcoBersnak, you can check now
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.