text: 
  SELECT e.emp_no,
      e.first_name,
      e.last_name,
      t.title,
      t.from_date,
      t.to_date
  INTO retirement_titles
  FROM employees e
  JOIN titles t
  ON (e.emp_no = t.emp_no)
  WHERE birth_date BETWEEN '1951-01-01' AND '1954-12-31'
  ORDER BY e.emp_no;
  
  -- Use Dictinct with Orderby to remove duplicate rows
  SELECT DISTINCT ON (emp_no),
       emp_no,
       first_name,
       last_name,
       title
  INTO unique_titles
  FROM retirement_titles
  WHERE to_date = '9999-01-01'
  ORDER BY emp_no, to_date DESC;
  
  -- Create a retiring titles table using Count
  SELECT COUNT(*),
      title
  INTO retiring_titles
  FROM unique_titles
  GROUP BY title
  ORDER BY 1 DESC;
  
  -- create a Mentorship Eligibility table that holds the employees
  -- who are eligible to participate in a mentorship program
  SELECT DISTINCT ON(e.emp_no)
      e.emp_no,
      e.first_name,
      e.last_name,
      e.birth_date,
      de.from_date,
      de.to_date,
      t.title
  INTO mentorship_eligibility
  FROM employees e 
  JOIN dept_employees de ON (e.emp_no = de.emp_no)
  JOIN titles t ON (e.emp_no = t.emp_no)
  WHERE to_date = '9999-01-01'
  AND birth_date BETWEEN '1965-01-01' AND '1965-12-31';
  