I have a table ‘node’ wich has a column ‘nid’. This id corresponds to the column ‘entity_id’ in three other tables. The three tables we’ll call ‘pop’, ‘city’, ‘state’. The ‘city’ and ‘state’ tables have city_value and state_value columns respectively.
Not all ‘city’ and ‘state’ table rows have a corresponding ‘entity_id’ in the ‘pop’ table.
From this I can get two sets of data. Nodes that have and entity_id in the pop table (setA) and those that don’t (setB).
To get setA I do this:
SELECT nid FROM node
LEFT OUTER JOIN pop
ON node.nid = pop.entity_id
WHERE pop.entity_id IS NOT null
I can’t figure out how to delete rows in ‘node’ from setB that have the same city and state as setA.
EDIT: I had m.entity_id in my setA code but it should have been pop.entity_id in the WHERE line.
EDIT: I think I have it.
SELECT DISTINCT setB.nid FROM
(
SELECT DISTINCT AA.nid, AA.title, BB.field_dialup_number_city_value, CC.field_dialup_number_state_value FROM
(
SELECT node.nid, node.title FROM node LEFT OUTER JOIN field_data_field_dialup_number_popcode pop
ON node.nid = pop.entity_id WHERE pop.entity_id IS NOT null
) AA
INNER JOIN field_data_field_dialup_number_city BB ON AA.nid = BB.entity_id
INNER JOIN field_data_field_dialup_number_state CC ON AA.nid = CC.entity_id
) setB
INNER JOIN
(
SELECT DISTINCT A.nid, A.title, B.field_dialup_number_city_value, C.field_dialup_number_state_value FROM
(
SELECT node.nid, node.title FROM node LEFT OUTER JOIN field_data_field_dialup_number_popcode pop
ON node.nid = pop.entity_id WHERE pop.entity_id IS null
) A
INNER JOIN field_data_field_dialup_number_city B ON A.nid = B.entity_id
INNER JOIN field_data_field_dialup_number_state C ON A.nid = C.entity_id
) setA
ON setA.field_dialup_number_state_value = setB.field_dialup_number_state_value
WHERE setA.field_dialup_number_city_value = setB.field_dialup_number_city_value
You said setA is
setB would be just a JOIN WHERE NULL
If you want setA to connect back to city and state, try this:
If you want setB to connect back to city and state, try this: