Sql qurey to get which sockets to command