I am using bunch of nested selects, joins and outer apply to get this result,

```
 ╔═════╦════════╦══════════╦ 
 ║ ID  ║ Name   ║ RandomID ║ 
 ╠═════╬════════╬══════════╬ 
 ║ 1   ║ a      ║     3    ║ 
 ║ 2   ║ b      ║     2    ║ 
 ║ 3   ║ c      ║     1    ║ 
 ╚═════╩════════╩══════════╩ 

```

What I want,

```
 ╔═════╦════════╦══════════╦══════════════╦ 
 ║ ID  ║ Name   ║ RandomID ║ Random Name  ║
 ╠═════╬════════╬══════════╬══════════════╬
 ║ 1   ║ a      ║     3    ║     c        ║
 ║ 2   ║ b      ║     2    ║     b        ║
 ║ 3   ║ c      ║     1    ║     a        ║
 ╚═════╩════════╩══════════╩══════════════╩

```

So if query prototype is,

```
Select ID, Name, dbo.SomeFunction(@ID)
FROM (Tables + Joins)
WHERE xxx

```

Now should I do inner join to the table which has ID and Name and get Random Name column from there or should I SOMEHOW join above query ?

I would like to keep performance in mind.