implement query join