Re: A list based table join?

*To*: mathgroup at smc.vnet.net*Subject*: [mg112979] Re: A list based table join?*From*: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>*Date*: Sat, 9 Oct 2010 06:33:58 -0400 (EDT)*References*: <i8jteq$aco$1@smc.vnet.net>

Here are a few possibilities: Cases[x, {q_, p_} /; MemberQ[y, q]][[All, 2]] Select[x, MemberQ[y, #[[1]]] &][[All, 2]] Pick[x[[All, 2]], MemberQ[y, #] & /@ x[[All, 1]]] Pick[x[[All, 2]], Or @@@ Outer[Equal, x\[Transpose][[1]], y]] Extract[x[[All, 2]], Position[x[[All, 1]], _?(MemberQ[y, #] &)]] Cheers -- Sjoerd On Oct 7, 9:39 am, Leo Ditolaghi <leoditola... at gmail.com> wrote: > Hi all, > > (noob Mathematica question:) > > If I have two lists, how do I determine the indices at which the 1st list > elements are matched by the elements of the second, and then use these > matching indices to extract corresponding columns in the 1st list (sort of a > simulated database join)? I.e., > > x = {{"hello", 27}, > {"bye", 30}, > {"hello", 54}, > {"seeya", 100}, > {"hi", 9}} > > y = {"hello", "hi"} > > where x is the source table, and y is the select criteria (so to speak.) > > I wish to produce z, where y defines which elements of x to extract: > > z = {27,54,9} > > I know this should be easy and elegant, but I am going in circles > with list functions. > > Thanks in advance, > > Leo