Without sorting or otherwise modifying the list, do the following:
SelectIndex[list_, fn_] := Module[{x}, x = Reap[For[i = 1, i < Length[list], i++, If[fn[list[[i]]], Sow[i], Null];]]; If[x[[1]] == {}, {}, x[[2, 1]]]] list={ {"foo",1}, {"bar",2}}; SelectIndex[list, StringMatchQ[
You can use this to retrieve records from a database
Lookup[list_, query_, column_: 1, resultColumns_: All] := list[[SelectIndex[list, StringMatchQ[query, #[[column]]] &], resultColumns]] Lookup(list,"foo")
source share