Here’s the situation:
- I have a main admin whose
id, in the tablepersonis478. - this admin is supposed to handle partners, in the table
partners. - there’s a table that “joins” them:
person_partners.
Sometimes, some people add new partners, and I’d like to run a query that:
- either:
- remove all links between this admin and partners, some kind of
DELETE * FROM person_partners where id_person=478 - re-insert all links between this admin and partners (= new partners will be inserted too), some kind of
INSERT INTO person_partners (id_person,id_partner) VALUES (478, SELECT id FROM partners)(but this query give me this error:ERROR 1242 (21000): Subquery returns more than 1 row)
- remove all links between this admin and partners, some kind of
- or simply insert all partners that are not yet in
person_partnerswithid_person=478
Any idea?
Like BugFinder said, “You seem to have your own answers in the question”
To fix the ERROR 1242 you have to write it like this:
Alternatively to “simply insert all partners that are not yet in person_partners with id_person=478” you can
Read more about it here.