Please advice on Query Tuning for below requirement.
I have 4 tables Table1....Table4. Where Table1 will be used for other three tables.
I have query something as below
;With Chk As
(
Select Distinct Col1 From Table1
)
Select Chk.Col1,
(Select Top1 Col2 From Table2 Where Chk.col1 = Table2.Col1
Group By Col1,col2
Order By Len(Col1) Desc) as'ABC',
(Select Top1 Col2 From Table3 Where Chk.col1 = Table2.Col1
Group By Col1,col2
Order By Len(Col1) Desc) as'PQR',
(Select Top1 Col2 From Table4 Where Chk.col1 = Table2.Col1
Group By Col1,col2
Order By Len(Col1) Desc) as'XYZ'
From Chk.
I am confused whether this query can be written using left joins or any other way.Please advice.
Please have look on the comment