Working on the sql queries