One important application of wireless sensor networks is tracking moving objects. The recent progress has made it possible for tiny sensors to have more computing power and storage space. Therefore, a sensor network can be considered as a distributed database, on which one can conduct in-network data processing. This paper considers innetwork moving object tracking in a sensor network. This typically consists of two operations: location update and query. We propose a message-pruning tree structure that is an extension of the earlier work [7], which assumes the existence of a logical structure to connect sensors in the network. We formulate this problem as an optimization problem. The formulation allows us to take into account the physical structure of the sensor network, thus leading to more efficient solutions than [7] in terms of communication costs. We evaluate updating and querying costs through simulations.