sugarquery

$query = "select km.contacts_cx_tco_orders_1contacts_ida as sd from contacts_cx_tco_orders_1_c ct join cx_tco_orders c on c.id = km.contacts_cx_tco_orders_1cnx_tco_orders_idb where c.id = '".$active."' and c.deleted=0 and km.deleted=0";

How can i write in SugarQuery?