sql - Nested Inner join query -


i have 4 tables called attr, data, extradata , syst. have multiple/nested inner joins attributes 4 tables, , running issues because of that. background, there column called 'id' in 'data' table obtaining inner join between data , extradata follows:

select x.id data x  inner join extradata xa  on x.dataid = xa.dataid  x.data = 'condition1' , not xa.additionaldata = 'condition2' 

this id has matched id in attr table, , 1 more inner join syst table. following abbreviated version of query that's i'm trying out:

select top(10) a.id  attr  inner join data x on a.id =  (     select x.id data x      inner join extradata xa      on x.dataid = xa.dataid      x.data = 'condition1' , not xa.additionaldata = 'condition2' ) inner join syst s on a.sysid = s.sysid s.desc = 'condition3' 

there (obviously) wrong query, i'd grateful suggestions. in advance!

assuming attr.id maps data.id, can join of tables , of conditions go in where clause:

select top(10) a.id  attr      inner join data x on a.id = x.id     inner join extradata xa on x.dataid = xa.dataid     inner join syst s on a.sysid = s.sysid x.data = 'condition1'    , not xa.additionaldata = 'condition2'   , s.desc = 'condition3' 

joining attr data allows join attr extradata, because data becomes link between 3.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -