Re: Re: How to do a SQL type operation???
- To: mathgroup at smc.vnet.net
- Subject: [mg64419] Re: [mg64392] Re: How to do a SQL type operation???
- From: Richard Palmer <mapsinc at bellatlantic.net>
- Date: Thu, 16 Feb 2006 03:05:31 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Thanks Ray and others. I was also able to do solve the problem with a
dispatch command. Figured it out after I sent the note.
On 2/15/06 3:32 AM, "Ray Koopman" <koopman at sfu.ca> wrote:
> 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
>
> Ah, the virtues of testing! In this case it showed
> the need to parenthesize the function in Scan.
>
> In[1]:= table1 = {{a,Xa},{b,Xb},{c,Xc},{d,Xd},{a,Xaa},{c,Xcc}}
> table2 = {{a,Ya},{b,Yb},{c,Yc},{d,Yd}}
> Module[{Y},Scan[(Y@#[[1]] = #[[2]])&, table2];
> Append[#, Y@#[[1]] ]& /@ table1]
>
> Out[1]= {{a,Xa},{b,Xb},{c,Xc},{d,Xd},{a,Xaa},{c,Xcc}}
> Out[2]= {{a,Ya},{b,Yb},{c,Yc},{d,Yd}}
> Out[3]= {{a,Xa,Ya},{b,Xb,Yb},{c,Xc,Yc},{d,Xd,Yd},
> {a,Xaa,Ya},{c,Xcc,Yc}}
>