Displaying different field based on null. (ex: display alias field if it is not null and name field if alias field is null. i.e., if user has alias and name both u just have to show alias if he has no alias u have to show name)

if rs is result then in php t will be

foreach($rs as $r)
{
   if($r['alias']=="")
   {
     echo $r['name'];
   }
   else
   {
     echo $r['alias'];
   }
}

But we can do a null check and different field value at query level itself.

selet coalesce(alias,name) as name  from profiles

coalesce will give first not null of what u sent. i.e., coalesce(null,null,0,null,’a’) will just give 0

With this method PHP code will only be

foreach($rs as $r)
{
   echo $r['name'];
}

Although we can use switch statements, its easier to do in query level as inbuilt functions are much more optimized towards performance