UPDATE advertises
SET logs = advertises.name || ' ' || advertises.province || ' ' || advertises.subdistrict || ' ' || advertises.regency || ' ' || (select pic_name from agents where id = advertises.agent_id) || ' ' || advertises.ads_id || ' ' || (select office_agents.name from agents join office_agents on agents.office_id = office_agents.id where agents.id = advertises.agent_id)
where office_id is not null and office_id != 0;
UPDATE advertises
SET logs = advertises.name || ' ' || advertises.province || ' ' || advertises.subdistrict || ' ' || advertises.regency || ' ' || (select pic_name from agents where id = advertises.agent_id) || ' ' || advertises.ads_id
where office_id is null or office_id = 0;