选择存在不工作wordpress

Hello stackoverflow community. I need help. I've got list of cities which belongs to companies. When i filter companies by category, i want to delete cities of companies if there are no company with that city. So I thought that i need to check if there are companies with that category and city. So I've tried:

$querystr = "
    SELECT EXISTS(SELECT * FROM $wpdb->term_relationships, $wpdb->postmeta
    WHERE $wpdb->term_relationships.object_id = $wpdb->postmeta.post_id  
    AND $wpdb->postmeta.meta_key = 'country'
    AND $wpdb->postmeta.meta_value = '$country_name'
    AND $wpdb->postmeta.meta_key = 'city'
    AND $wpdb->postmeta.meta_value = '$city_name
    AND $wpdb->term_relationships.term_id = '$company_category'')
 ";
 $pageposts = $wpdb->get_results($querystr);

But that doesnt work, can you help me? :/

AND $wpdb->postmeta.meta_value = '$city_name
AND $wpdb->term_relationships.term_id = '$company_category''

Check $city_name and $company_category.  you have an extra `'` at the end

Can post the error msg. The it would be more easy to find the solution.