99% done of sql part

blala