how to get an object to follow another?

how do i get an object to stay on the same x and z axis of another object but not the y axis? i cant seem to work out how to get vector3 from transform.translate.
thanks for any assistance

transform.position = new Vector3(target.transform.position.x, transform.position.y, target.transform.position.z);

or

transform.Translate(target.transform.position.x - transform.position.x, 0, target.transform.position.z - transform.position.z);