title: SQL Server get oldest and youngest
body: <p>I have a table of people with their birthdates, would like to know the youngest and the oldest person.</p>
  
  <p>I am trying to write this code, but it is not valid. How would I do so?</p>
  
  <pre><code>SELECT [CustNo]
        ,[name]
        ,[address]
        ,max([Date of Birth]) and min([Date of Birth]), 
        ,[id]
    FROM [Bharath].[dbo].[Customer]
  </code></pre>
  
  <p>This is the table</p>
  
  <p><img src="https://i.stack.imgur.com/RlLll.jpg" alt="enter image description here"></p>
  
  <p>Another code that I am trying to do.</p>
  
  <pre><code> SELECT  CustNo, name, address, DATEDIFF(YEAR, [Date of Birth], GETDATE()) AS Age
  FROM bharath.dbo.Customer
  INNER JOIN (SELECT min [Date of Birth] y , Max [Date of Birth] z FROM Customer) a
   on a.y=dob 
   or a.z=dob
  </code></pre>
  
  <p>This is the code that is working perfectly with all my needs</p>
  
  <pre><code>select [CustNo], [name], [address],datediff(year, [date of birth], getdate()) as age , CONVERT(VARCHAR(10),[Date of Birth],105)
  from Bharath.dbo.Customer
  where [Date of Birth] = (select max([Date of Birth]) from Bharath.dbo.Customer) 
  or [Date of Birth] = (select min([Date of Birth]) from Bharath.dbo.Customer)
  </code></pre>