SQL testing

SQL works. Needs a lot of cleanup though.