Complex table Join at sql -


[my tables diagram ]

pls want data articles table according presskit table data

i need how join between articles table , presskit table

while have different intermediate tabled between them?

i want data

 select articleid ,         articaletile    articles   dbo.magazineid in (         select  dbo.magazines.magazineid            dbo.magazines                 inner join dbo.presskitmagazines on dbo.magazines.magazineid = dbo.presskitmagazines.magazineid           presskitid = @presskitid )         , classid in (         select  class.classid            dbo.class                 inner join dbo.presskitclass on class.classid = presskitclass.classid           presskitid = @presskitid ) 

select articleid, articletitle articles join dbo.presskitmagazines pm on a.magazineid = pm.magazineid , pm.presskitid = @presskitid join dbo.presskitclass pc on a.classid = pc.classid , pc.presskitid = @presskitid 

you not need involve magazines, class or presskit because not need return names associated ids. didn't need them in original query either:

select articleid, articletitle articles magazineid in (     select magazineid     dbo.presskitmagazines     presskitid = @presskitid ) , classid in (     select classid     dbo.presskitclass     presskitid = @presskitid ) 

suppose table t holds rows make statement parameterized columns true statement. eg articles holds rows satisfy:
    "article articleid titled articletitle in magazine magazineid & of class classid"
or in shorthand:
    article(articleid, articletitle, magazineid, classid)
inside sql select statement, table's column names prefixed alias , dot (which can left out when there's no ambiguity):
    a(a.articleid, a.articletitle, a.magazineid, a.classid)
rows in:
    select c u c in (select c t wherecondition)
or prefixes , dots:
    select u.c u u.c in (select t.c t wherecondition)
rows where:
    select u.c u join t onconditionand u.c = t.c
because both return rows column c where:
    u(...,u.c,...) , t(...,t.c,...) , condition , u.c = t.c

for composing queries see this answer.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -