Here is my problem,
I have to build a query in mysql
with join statements...
my database tables look like this :
table 1:
contact, with contact_id, contact_value, contact_relation
table 2 :
relation, with relation_id, relation_one, relation_two
I have to delete from contact where contact have relation value (a relation id) AND all of these relations but ONLY where my relation_one is equal to a predefined value...
so the actual idea I have, is this one :
DELETE FROM 'relation' INNER JOIN contact ON contact.contact_relation = relation.relation_id WHERE relation_one = MyValue
But it is NOT doing what I mean...
I try it this way in my mysql
:
DELETE relation.* FROM `relation` INNER JOIN `contact` ON `contact`.`contact_relation`=`relation`.`relation_id` WHERE `relation_one` = 48
I assume that this might look like a stupid question... even an "already answered one", BUT i looked through stack, found similar but did not solve my problem because when I apply this query, it deletes ALL relations WHERE relation_one = 48
, NOT ONLY the ones I need... (I mean those which are referenced into the contact table under the contact_relation (which is the id of the relations I MAY delete, if these relations have relation_one
set at 48 ONLY!)
I mean: I can have 100 records in relation table, where relation_one
IS 48... but i only want to delete these "relations" where the relation_id = contact_relation
... my contact.contact_relation
is null
in most cases... but sometimes, for 2/100 it is an existing relation_id
written there... these are the relations I "may have to" delete...