Move SQL to the controller