codice:
dim previous = null

dim rs = select * from join_tre_tabelle

print "<ul>"

while(dim record = rs.next()) do

if record.id_fotografo <> previous then
  print "[/list]" if not previous is null
  print "[*]" + record.nome_fotografo
  print "<ul>"
  previous = record.id_fotografo
end if

print "[*]" + record.tipologia_foto + ""

loop;

if rs.recordCount > 0 then print "[/list]"

print "[/list]"

rs.close()

end;

traducitelo e hai il tuo algoritmo