homerUK
04-24-2006, 03:22 PM
Hi,
I need an SQL statement to find (and eventually) delete and redundant records in my database.
The structure is
TABLE: Survey
surveyID
etc etc
TABLE: Responses
responseID
surveyID
etc etc
So I need to find all the records in responses that DO NOT have a surveyID which is valid. Ie: Any records which have a surveyID that does not exist any longer.
I have done this
SELECT
s.surveyID as survey_surveyID,
r.surveyID as repsonse_surveyID
FROM survey s
left outer join responses r on
r.surveyID != s.surveyID
but it seems to be bringing back records which have a valid survey. Ie: The survey still exists in the survey table.
Thanks for any help!
I need an SQL statement to find (and eventually) delete and redundant records in my database.
The structure is
TABLE: Survey
surveyID
etc etc
TABLE: Responses
responseID
surveyID
etc etc
So I need to find all the records in responses that DO NOT have a surveyID which is valid. Ie: Any records which have a surveyID that does not exist any longer.
I have done this
SELECT
s.surveyID as survey_surveyID,
r.surveyID as repsonse_surveyID
FROM survey s
left outer join responses r on
r.surveyID != s.surveyID
but it seems to be bringing back records which have a valid survey. Ie: The survey still exists in the survey table.
Thanks for any help!