SQL select testing and fix.