finding the people who have a missing data item

  • Our database of clients keeps the date of the clients' annual visit. However, some of them did not come for several years, then out of the blue came in in 2008. I need to query for the people that came in past years, but did not show up in 2007, only to reappear in 2008. They are considered reenrollees. Our current system will show the people who are new, with no past visits, or the people who are returning.

    I have tried to use a where exists and where not exists queries to no avail....ny suggestions ?

    I would need to find the people who did not have visits in 2007 but did have them in 2008. A bonus would be to identify those who also had visits before 2007 but not in 2007, only to return in 2008.

    Thank you !!!!

  • Can you post the actual queries you are building, it could help. We also need the schema of the tables involved.

    We do not know what tables you are using, or whatever field you are joining on, help us help you! 😉

    Cheers,

    J-F

  • my table consists of two columns, NAME and YEAR. When the person visits, we record their name the current year. The queries I used/came up are in the trash. I initially used

    select name,year

    from visit

    where not exists

    (select name,year

    from visit

    where year=2007)

    and now that I see what I did, I assume that I need to have a table of just names and link it to the visits table so tht I can get those in the name table that dont have a corresponding 2007 entry in the visits table. Any ideas on how ?

  • The following query returns all the clients who visited in 2008 and the year that the client previously visited or NULL if their first visit was in 2008). If I understand your requirements correctly, you should be able to categorise your clients based on the results of this query.

    SELECT V1.Name, PreviousYear = MAX(V2.Year)

    FROM Visit V1

    LEFT OUTER JOIN Visit V2 ON (V1.Name = V2.Name AND V2.Year < 2008)

    WHERE (V1.Year = 2008)

    GROUP BY V1.Name

    ORDER BY V1.Name

  • Thank you !!!! It works very well. I took it a step further and used your suggestion to select into a temp file, then took that temp file, joined it back to the originall file, and reselected to get only those with an active visit in 2008. The people not seen in 2008 are off the list. My end result is a list people active this year with their last date/year of activity. Perfect.

    Little by little I learn...Thank you !!

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply