How to Display Unique Values from database using db_select in Drupal i tried with following code but i cant get the attached output 

$query = db_select('webform_submitted_data', 'u');
$query-&gt;fields('u', array('sid','nid','data'));
$query-&gt;condition('nid','49','=');
$results =$query-&gt;execute();

echo "&lt;table&gt;";
echo "&lt;tr&gt;";
echo "&lt;th&gt;Name &lt;th&gt;";
echo "&lt;th&gt;Post &lt;th&gt;";
echo "&lt;/tr&gt;";
while($record = $results-&gt;fetchAssoc())
{
 $sid = $record['sid'];
 $nid = $record['nid'];
$submission = webform_get_submission($nid,$sid);
echo "&lt;tr&gt;";
echo $submission-&gt;data[1][0];
echo $submission-&gt;data[2][0];
echo "&lt;/tr&gt;";
}
echo "&lt;/table&gt;";
}
Try

$query = db_select('webform_submitted_data', 'u');
$query-&gt;fields('u', array('sid','nid')); $query-&gt;condition('nid','49','=');
$results =$query-&gt;distinct()-&gt;execute();


Api info about unique