Generalisation_of_some_sql_code