check if user exists I want to check if user exists based on some profile2 field. I have tried the following. Works fine. I want to know if it is proper or not. If it is not proper, is there any other way around?

function checkUserExistsByProfile($company_id){

        $query = 'SELECT field_somefield_value
        FROM {field_data_field_somefield} AS fn
        WHERE fn.field_somefield_value  =:rids';
        $result = db_query($query, array(':rids' =&gt; array($company_id)));

        $field_value = $result-&gt;fetchCol();
        return count($field_value);

    }


Please suggest.

UPDATE:

I have tried solutions suggested by  Mołot, Bulat as follows.

Profile Field name is field_ngouniqueid

$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'user')
-&gt;fieldCondition('field_ngouniqueid', 'value', (int)$company_id, '=');
$results = $query-&gt;execute();

$users = user_load_multiple(array_keys($results['user']));


But users is an empty array always. But it has a record with value $company_id

Solution:
it should be $query->entityCondition('entity_type', 'profile2')
To get the users filtered based on profile2 field, field_ngouniqueid is created through profile2

$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'profile2')
-&gt;fieldCondition('field_ngouniqueid', 'value', (int)$company_id, '=');
$results = $query-&gt;execute();

$users = user_load_multiple(array_keys($results['user']));