copied sql used from gdoc