Extending a long SQL with inner joins (server 2000) -


recently friendly user on stackoverflow helped me sql:

 select (select top 1                  a.id            vanalyseshistory            a.companyid = n.stockid         order a.chosendatetime desc) id,         n.name,          (select top 1                  a.chosendatetime             vanalyseshistory            a.companyid = n.stockid         order a.chosendatetime desc) chosendatetime    vstocknames n  

which working great. want extend sql. in table vanalyseshistory there attribute called analyseid. rows analyseid = 3 example.

my try:

 select (select top 1                  a.id            vanalyseshistory            a.companyid = n.stockid , analyseid = 3        order a.chosendatetime desc) id,         n.name,          (select top 1                  a.chosendatetime             vanalyseshistory            a.companyid = n.stockid , analyseid = 3        order a.chosendatetime desc) chosendatetime    vstocknames n  

the problem there isnt analyses analyseid = 3 every row in vstocknames. therefore of rows returned has null in id , chosendatetime.

can me? want rows there exists , analyse analyseid example analyseid = 3.

and oh ye, server 2000.

thanks in advance

i used approach:

select     b.id, c.chosendatetime, n.name         (select     companyid, max(chosendatetime) chosendatetime                                 vanalyseshistory                             (analyseid = 3)                        group companyid) c inner join                       vanalyseshistory b on c.companyid = b.companyid , c.chosendatetime = b.chosendatetime , b.analyseid = 3 inner join                       vstocknames n on n.stockid = c.companyid order n.name 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -