Fix query in function get_id