Get min and max row from table
One way to do this is using window functions:

SELECT DISTINCT
    type_id, book_id, title_id, page_id,
    first_value(lines)      OVER wmin AS min_lines, 
    first_value(created_at) OVER wmin AS min_created_at, 
    first_value(lines)      OVER wmax AS max_lines,
    first_value(created_at) OVER wmax AS max_created_at
FROM 
    tableX
WINDOW 
    wmin AS (PARTITION BY type_id, book_id, title_id, page_id 
             ORDER BY lines ASC, created_at ASC), 
    wmax AS (PARTITION BY type_id, book_id, title_id, page_id 
             ORDER BY lines DESC, created_at ASC) ;


Tested at SQLfiddle.