title: SQL: How to select only the oldest record
body: <p>I realize this is a question that has been asked previously but upon investigating those posts, none of them fit exactly what I'm working on.</p>
  
  <p>I have a list of people who have visited a location, many of which have visited multiple times. Each person has a unique ID, and each visit has a date and a status (I'm looking only at visits with a status of 'unchanged,' as opposed to 'canceled,' 'rescheduled,' etc.). What I need to be able to do is select only the oldest record for each person. In other words, see only the date of their very first visit.</p>
  
  <p>I've solved a problem like this before and I went back and found my old code and attempted to apply it to this particular situation. The issue is that back then, I was trying to pull the most <em>recent</em> record for a given person, and I'm not sure how to change what I have here to apply to the <em>oldest</em> record. If one person has had 3 visits and another has had 7, I don't know what to do with my <code>seqnum</code> variable.</p>
  
  <p>Also, if I run this code below the way it currently is, I'm still getting multiple records for each person, which is another problem entirely. At least the filter for unchanged visits is working.</p>
  
  <p>Any thoughts?</p>
  
  <pre><code>SELECT DISTINCT
    PersonID,
    PersonName,
    VisitDate,
    Status,
    VisitType
  
  FROM (SELECT VisitInfo.*,
        ROW_NUMBER() OVER (PARTITION BY PersonID, VisitDate ORDER BY VisitDate DESC) as seqnum
        FROM VisitInfo
        WHERE Status = 'Unchanged'
  
        ) VisitInfo
  
  WHERE seqnum = 1
  ORDER BY VisitDate
  </code></pre>