How can I remove duplicate value? I have used custom code. I want to remove duplicate value using distinct, how can I do this? My code is like this.

$media_query = db_select('node','n');
    $media_query-&gt;innerJoin('field_data_field_media_room_type','mtype','mtype.entity_id = n.nid');
    $media_query-&gt;fields('n',array('nid'));
    $media_query-&gt;fields('mtype',array('field_media_room_type_tid'));
    $media_query-&gt;condition('n.type','media_room_page','=');
    $media_query-&gt;condition('mtype.field_media_room_type_tid',$media_id,'=');
    $media_res = $media_query-&gt;execute();       
    while($media_fetch = $media_res-&gt;fetchObject()){
     $media_year = '';
        if(isset($media_node-&gt;field_year['und'][0]) &amp;&amp; $media_node-&gt;field_year['und'][0] !=''){
            $media_year = $media_node-&gt;field_year['und'][0]['value'];
        }
      echo'&lt;pre&gt;';print_r($media_year);
    }


Output like this:

2011

2011 

2011 

2011 

2011 

2011 

2012 

2012 

2013 

I want to remove duplicate values so how can I remove it?
You can try like 

 $media_query = db_select('node','n')
         -&gt;distinct()-&gt;innerJoin('field_data_field_media_room_type','mtype','mtype.entity_id = n.nid');
        -&gt;fields('n',array('nid'));
        -&gt;fields('mtype',array('field_media_room_type_tid'));
        -&gt;condition('n.type','media_room_page','=');
        -&gt;condition('mtype.field_media_room_type_tid',$media_id,'=');
        $media_res = $media_query-&gt;execute();       
        while($media_fetch = $media_res-&gt;fetchObject()){
         $media_year = '';
            if(isset($media_node-&gt;field_year['und'][0]) &amp;&amp; $media_node-&gt;field_year['und'][0] !=''){
                $media_year = $media_node-&gt;field_year['und'][0]['value'];
            }
          echo'&lt;pre&gt;';print_r($media_year);
        }


or 

you can use Group By for that particular column.