sql - How to rewrite a subquery to use joins when you used DISTINCT in the subquery? -


i have query use sub query, , rewrite join, have better performance.

the subquery uses distinct there many records, , problem have end multiple times in join when use join.

so how rewrite query use join:

select *    table1         join table2 b           on b.field1 = a.field1   b.field3 = 1531         , a.field4 = 0         , a.field5 in (select distinct field5                            table3                           field6 = 172)  

something like:

select *    table1         join table2 b on b.field1 = a.field1         join ( select distinct field5                            table3                           field6 = 172 ) c         on c.field5 = a.field5   b.field3 = 1531 , a.field4 = 0  

it's hard without seeing actual data, if doesn't work, please let me know.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -