correcting sql queries