reordered sql queries