Fixed sql queries