refactoring code sql for add and display separated