Fix SQL query in pop_job_from_pending_queue

The SQL query in pop_job_from_pending_queue wasn't right, this was manifesting as a test failure in test_equal_priority.