Wykombinowałem takie zapytanie:
SELECT n.id
FROM nodes n
LEFT JOIN nodeassignments ON n.id = nodeassignments.nodeid
LEFT JOIN assignments ON nodeassignments.assignmentid=assignments.id
WHERE (assignments.dateto > unix_timestamp() or assignments.dateto='0' )
AND assignments.datefrom < unix_timestamp()
AND assignments.suspended = 0
AND access = '0'
AND (SELECT SUM(value) FROM cash WHERE customerid = n.ownerid) >= 0
wykonuje się ładnie i szybko. ale jeśli wrzucę to do update:
UPDATE nodes SET warning=0, access=1 WHERE id IN (
SELECT n.id
FROM nodes n
LEFT JOIN nodeassignments ON n.id = nodeassignments.nodeid
LEFT JOIN assignments ON nodeassignments.assignmentid=assignments.id
WHERE (assignments.dateto > unix_timestamp() or assignments.dateto='0' )
AND assignments.datefrom < unix_timestamp()
AND assignments.suspended = 0
AND access = '0'
AND (SELECT SUM(value) FROM cash WHERE customerid = n.ownerid) >= 0
)
to mysql krzyczy:
#1093 - You can't specify target table 'nodes' for update in FROM clause
--
Pozdrawiam
Marcin / nicraM