MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to do a SQL type operation???

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64365] Re: [mg64352] How to do a SQL type operation???
  • From: Pratik Desai <pdesai1 at umbc.edu>
  • Date: Tue, 14 Feb 2006 01:31:41 -0500 (EST)
  • References: <200602130815.DAA12582@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Richard Palmer wrote:

>Assume Table1={{a,Xa},{b,Xb},...,{n,Xn},...} where the key a can occur many
>times and Xa is different each occurrence.
>
>We also have table2={{a,Ya},{b,Yb},...,{n,Yn}}. Here a,b,...,n occur exactly
>once. 
>
>How do I create table3={{a,Xa,Ya},{b,Xb,Yb},...,{n,Xn,Yn},...} by joining
>the tables on the first column?
>
>From the problem, if a (or b or c or ...  n} is in table1, it is also in
>table1 and visa versa.
>
>The a,b,...,n,... Are small positive integers.
>
>Thanks
>
>  
>
Perhaps something like this using unsortedunion (please see help on Union)
In[59]:=
v1={{a,Xa},{b,Xb},{c,Xc},{d,Xd}}
v2={{a,Ya},{b,Yb},{c,Yc},{d,Yd}}
UnsortedUnion[x_]:=Module[{f},f[y_]:=(f[y]=Sequence[];y);f/@x]
Partition[UnsortedUnion[Flatten[Transpose[{v1,v2}]]],3]

Out[59]=
{{a,Xa},{b,Xb},{c,Xc},{d,Xd}}

Out[60]=
{{a,Ya},{b,Yb},{c,Yc},{d,Yd}}

Out[62]=
{{a,Xa,Ya},{b,Xb,Yb},{c,Xc,Yc},{d,Xd,Yd}}


  • Prev by Date: Re: Comparison of Mathematica on Various Computers
  • Next by Date: Polygons
  • Previous by thread: How to do a SQL type operation???
  • Next by thread: Re: How to do a SQL type operation???