I need to select all from table1 where active=1 and replace t1cid,t2cid,L1cid,L2cid---L10cid with corresponding name of cid in table2.
I have two tables like,
Table1 column names
id
name
t1cid
t2cid
L1cid
L2cid
L3cid
L4cid
L5cid
L6cid
L7cid
L8cid
L9cid
L10cid
active
Table2
cid
ctype
cname
I need to merge these two tables and produce the output like,
final table
id
name
t1cname
t2cname
L1cname
L2cname
L3cname
L4cname
L5cname
L6cname
L7cname
L8cname
L9cname
L10cname
You could join
Table2toTable1multiple times, once for each column:Or, alternatively, you could join the tables once and then group the results:
I think the first solution ought to be faster, especially if you have indexes on
Table2.cidand the foreign key columns inTable1—but perhaps it’s worth benchmarking the two approaches to see which is better?