Hi all, If my post is irrelevant to the list, please let me know. I have conditions (REGEXP 'STRING' or ='STRING') as JOIN condition or as WHERE clause condition, i wonder for a 10 table LEFT/INNER JOIN query, which approach is better and why.
Thanks, ran i.e. " SELECT "+ " m.id_company, "+ " m.name, "+ " m.division, "+ " m.is_deleted, "+ " GROUP_CONCAT( DISTINCT pt.name,':\t',p.valueSEPARATOR '\n') AS phone_concat "+ " FROM "+ " crm_company m "+ " INNER JOIN "+ " crm_company m1 "+ " ON "+ " m1.id_company = m.id_company "+ " AND "+ " (m.name REGEXP '^"+q+"| "+q+"' "+ " OR m.division REGEXP '^"+q+"| "+q+"') "+ " LEFT JOIN "+ " crm_communication_company_link pmk "+ " ON pmk.id_company = m.id_company "+ " LEFT JOIN "+ " crm_communication p ON pmk.id_communication = p.id_communication "+ " LEFT JOIN "+ " crm_communication_type pt ON p.id_communication_type = pt.id_communication_type "+ " LEFT JOIN "+ " crm_customer_company_link cmk "+ " ON cmk.id_company = m.id_company "+ " LEFT JOIN "+ " crm_has_contact hc "+ " ON hc.cid = cmk.id_customer "+ _GROUP_CTRL + " WHERE "+ " m.is_deleted = 0 "+ " GROUP BY "+ " m.id_company "+ " ORDER BY "+ " m.name REGEXP '^"+q+"' DESC, "+ " m.name ASC "; Compare to that moved to WHERE clause: " SELECT "+ " m.id_company, "+ " m.name, "+ " m.division, "+ " m.is_deleted, "+ " GROUP_CONCAT( DISTINCT pt.name,':\t',p.valueSEPARATOR '\n') AS phone_concat "+ " FROM "+ " crm_company m "+ # self inner join removed " LEFT JOIN "+ " crm_communication_company_link pmk "+ " ON pmk.id_company = m.id_company "+ " LEFT JOIN "+ " crm_communication p ON pmk.id_communication = p.id_communication "+ " LEFT JOIN "+ " crm_communication_type pt ON p.id_communication_type = pt.id_communication_type "+ " LEFT JOIN "+ " crm_customer_company_link cmk "+ " ON cmk.id_company = m.id_company "+ " LEFT JOIN "+ " crm_has_contact hc "+ " ON hc.cid = cmk.id_customer "+ _GROUP_CTRL + " WHERE "+ " m.is_deleted = 0 AND ("+ " AND "+ " (m.name REGEXP '^"+q+"| "+q+"' "+ " OR m.division REGEXP '^"+q+"| "+q+"') ) "+ " GROUP BY "+ " m.id_company "+ " ORDER BY "+ " m.name REGEXP '^"+q+"' DESC, "+ " m.name ASC ";