Some SQL fixed

Still isn't complete