My SQL, circular, inefficient ... or neither?
Can someone have a look at this SQL and tell me if it is circular or inefficient? When I run it without restricting it one person it seems to run forever. This could just be the volume if there are no obvious errors in my SQL.
Table “Place” contains a list of locations with all their details including who is responsible for visiting that location and the last date that it was visited on. However in some instances this date is incorrect and does not match up with the data in the “Visits” table.
Table “Visits” lists all the visits to the locations, including a location reference number and the date of that visit.
Code:
SELECT s.user_num, s.place_ref
FROM
places s
WHERE
s.last_visit_date <> (SELECT
MAX(v.visit_date)
FROM
visits v
WHERE
v.place_ref = s.place_ref)
--AND
-- s.user_num = '000743'
ORDER BY
s.user_num, s.place_ref