I have a html search form which is like bellow image : 

[![enter image description here](https://i.stack.imgur.com/ZcdF1.png)](https://i.stack.imgur.com/ZcdF1.png)

In this search form I need to **search data from 7 tables**. In this 7 tables there are more than 11K data stored. So that I am using following sql `JOIN` query to get the result. 

But it's taking loooong time to get the result (sometime showing error message) if for e.g. I search for **Family Name = s**. I mean if there are huge data in the table columns. How can solve this issue ? I used `LIMIT` but I think it's not helpful in this query because first I have to search to all 7 tables !

**Sql Query:**

```
$getSearch .= " cd.cdid, cd.family_name, cd.given_name, cd.department, cd.title, company.cid, company.company_name, users.nickname, contact_label.label_data  FROM
            contact_details as cd
            LEFT JOIN users ON users.user_id = cd.user_id
            LEFT JOIN company ON company.cid = cd.cid
            LEFT JOIN contact_docs ON contact_docs.cdid = cd.cdid
            LEFT JOIN userkeywords ON userkeywords . cdid = cd . cdid
            LEFT JOIN keywords ON keywords . kid = userkeywords . kid
            LEFT JOIN contact_label ON contact_label.cdid = cd.cdid
            WHERE 1=1 ";

    if(!empty($ad_company)){
        $getSearch .= "AND company.company_name LIKE '$ad_company%' ";
    }
    if(!empty($ad_fname)){
        $getSearch .= "AND cd.family_name LIKE '$ad_fname%' ";
    }
    if(!empty($ad_department)){
        $getSearch .= "AND cd.department LIKE '$ad_department%' ";
    }

    if(!empty($ad_mp)){
        $getSearch .= "AND cd.mp >= '$ad_mp' "; 
    }
    if(!empty($ad_e2)){
        $getSearch .= "AND cd.e2 >= '$ad_e2' "; 
    }
    if(!empty($ad_pl)){
        $getSearch .= "AND cd.pl >= '$ad_pl' "; 
    }
    if(!empty($ad_ap)){
        $getSearch .= "AND cd.ap >= '$ad_ap' "; 
    }
    if(!empty($ad_j2)){
        $getSearch .= "AND cd.j2 >= '$ad_j2' "; 
    }

    if(!empty($ad_agreater)){
        $getSearch .= "AND cd.age >= '$ad_agreater' ";  
    }
    if(!empty($ad_aless)){
        $getSearch .= "AND cd.age <= '$ad_aless' "; 
    }
    if(!empty($ad_agreater) && !empty($ad_aless)){
        $getSearch .= "AND cd.age BETWEEN '$ad_agreater' AND '$ad_aless'";  
    }

    if(!empty($ad_sgreater)){
        $getSearch .= "AND cd.comp >= '$ad_sgreater' "; 
    }
    if(!empty($ad_sless)){
        $getSearch .= "AND cd.comp <= '$ad_sless' ";    
    }
    if(!empty($ad_sgreater) && !empty($ad_sless)){
        $getSearch .= "AND cd.comp BETWEEN '$ad_sgreater' AND '$ad_sless'"; 
    }

    if(!empty($ad_noteterm)){    
        $ad_noteterm = preg_replace("/\{ASUSIBBIR\}(.+?)\s:\s(.+?)\{ASUSIBBIR\}/m", "$2", $ad_noteterm);
        $getSearch .= "AND LOCATE('$ad_noteterm', REPLACE (notesUpdate, '{ASUSIBBIR}', ' '))";
    }

    if(!empty($ad_cnote)){    
        $getSearch .= "AND LOCATE('$ad_cnote', cd.characterNotes)"; 
    }
    if(!empty($ad_twork)){    
        $getSearch .= "AND contact_label.label_data LIKE '%$ad_twork%'";    
    }
    if(!empty($ad_tmobile)){    
        $getSearch .= "AND cd.mobile_phone like '%$ad_tmobile%'";   
    }

    if(!empty($ad_resume)){    
        $getSearch .= "AND LOCATE('$ad_resume', contact_docs.file_content)";    //is this the resume? yes
    }

    if(!empty($ad_datefrom) && empty($ad_dateto)){    
            $getSearch .= "AND cd.created_date BETWEEN '$ad_datefrom'AND '$date'";  
    }

    if(!empty($ad_dateto) && empty($ad_datefrom)){    
        $getSearch .= "AND cd.created_date BETWEEN date('0000-00-00') AND '$ad_dateto' "; 
    }

    if(!empty($ad_datefrom) && !empty($ad_dateto)){
        $getSearch .= "AND cd.created_date BETWEEN '$ad_datefrom' AND '$ad_dateto'";    
    }

    if(!empty($ad_type)){    
        $getSearch .= "AND cd.type = '$ad_type' ";  
    }

    if(!empty($ad_wemail)){
        $getSearch .= "AND cd.email LIKE '$ad_wemail%'";    
    }

    if(!empty($ad_pemail)){
        $getSearch .= "AND cd.email_private LIKE '$ad_pemail%'";    
    }

    if(!empty($ad_title)){
        $getSearch .= "AND cd.title LIKE '$ad_title%'"; 
    }

    if(!empty($ad_source)){
        $getSearch .= "AND cd.source LIKE '$ad_source%'";   
    }

    if(!empty($ad_consultant)){
        $getSearch .= "AND users.nickname LIKE '%$ad_consultant%'"; 
    }

    if(!empty($ad_keyword)){
        $ad_keyword_param = str_replace(",","','",$ad_keyword);
        $getSearch .= " AND keywords.keywordName IN ('$ad_keyword_param') ";
    }

    $getSearch .= " GROUP BY cd.user_id, cd.cid, cd.cdid ";

    if(!empty($ad_keyword)){
        $ad_keyword_param = str_replace(",",",",$ad_keyword);
        $getSearch .= " ) as a WHERE keywordName LIKE '$ad_keyword_param%' ";
    }

    $f = microtime(true);
    //$getSearch .= "ORDER BY cd.given_name ASC";
    $getSearch .= "ORDER BY cd.given_name DESC LIMIT 10";
    $getSearch =  mysqli_query($link, $getSearch);

```