Ripeto, solo tramite sql non mi risulta sia fattibile ciò che chiedi. In php una possibile soluzione è questa:
Codice PHP:
$query = mysql_query("select
case when categoria = 'a' then id end as a,
case when categoria = 'b' then id end as b,
case when categoria = 'c' then id end as c
from tabella") or die(mysql_error());
$str = '';
while ($row = mysql_fetch_assoc($query)) {
$row['a'] != NULL ? $arr['a'][]= $row['a'] : '';
$row['b'] != NULL ? $arr['b'][]= $row['b'] : '';
$row['c'] != NULL ? $arr['c'][]= $row['c'] : '';
}
$righe = max(count($arr['a']),count($arr['b']),count($arr['c']));
$str.= '<table>';
for ($i = 0; $i < $righe; $i++) {
$str.='<tr>';
array_key_exists($i,$arr['a']) ? $str.='<td>'.$arr['a'][$i].'</td>' : $str.='<td></td>';
array_key_exists($i,$arr['b']) ? $str.='<td>'.$arr['b'][$i].'</td>' : $str.='<td></td>';
array_key_exists($i,$arr['c']) ? $str.='<td>'.$arr['c'][$i].'</td>' : $str.='<td></td>';
$str.='</tr>';
}
$str.='</table>';
echo $str;