Superstructure models used in optimal damper problem are usually connected rigidly to ground, and ground effects are not taken into account. This study reveals the effect of relative density of sandy soils on the damper problems. The optimal distribution of viscous dampers and the effect of relative density of sandy soils on the dynamic response of structure for an n-storey shear-building model are examined. The governing equation of soil–structure model is established and the equations in the frequency domain are derived using Fourier transformation. Steepest direction search algorithm is used as an optimization method. The four different objective functions, which are the top displacement, top absolute acceleration, base shear and base moment behaviour of the structure defined in the frequency domain, are minimized. The fundamental mode response of structural model is taken into account, and the time history analyses are conducted by using El Centro (NS) earthquake acceleration record. The effect of relative density of sandy soils on the responses of structure with optimal design and the effect of the variation of total damper capacity used in the optimization stage are investigated. It is observed that the variation of the objective functions, total damping capacity and ground conditions can change the optimal design. The low displacement in damped systems has occurred in comparison with no damper. The structural response in the rigid case is less than those in the different relative density of sandy soils. The added dampers placed according to the different objectives have improved the structural response and also reduced the harmful effects caused by poor ground conditions.