Updated query to work in Oracle