complex querys help needed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wizardry
    New Member
    • Jan 2009
    • 201

    complex querys help needed

    hello -

    I'm trying to pull the data from multiple views of the data table, for one unique user id. the data is pulling i modified the testing data to verify that it was pulling correct, its just that the 3 row of data is correct except the name column. it replicates the first row name, not the actual name in the column. attached is my code for the query.

    thanks in advance for you help.


    Code:
    select 
    c.Bulletin as Bulletin,
    b.Title as Title,
    c.Date as Date,
    d.ProfileName as Name,
    g.Path as Path 
    from
    ManyTitle as a 
    left join Title as b
    on (a.TitleId=b.Id)
    left join Bulletin as c
    on (c.TitleId=a.TitleId),
    WebInfo as d
    left join ManyAlbums as e
     on (e.UserId=d.UIdFk)
    left join Title as f
    on (f.AlbumId=e.AlbumId)
    left join Data as g
    on (g.TitleId=f.Id)
    where a.UserId=d.UIdFk
    and a.UserId = any ( select FriendId from Friends )
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    I have no clue what you are trying to tell/ask us. Could you please explain a bit more?

    Steven

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      Not being completely awake at the moment, that query is a bit big for me to fully take in xD

      But, the WebInfo table, from which you pull the name column, is joined with a generic INNER JOIN (comma) without specifying an ON filter.

      That's usually not a good thing, as it creates filter-less result tables, where everything is joined with everything.

      Try adding a ON clause to that. Like:
      [code=sql]select
      c.Bulletin as Bulletin,
      b.Title as Title,
      c.Date as Date,
      d.ProfileName as Name,
      g.Path as Path
      from ManyTitle as a
      left join Title as b
      on (a.TitleId=b.Id )
      left join Bulletin as c
      on (c.TitleId=a.Ti tleId)
      INNER JOIN WebInfo as d
      on a.UserId=d.UIdF k
      and a.UserId = any (
      select FriendId from Friends
      )
      left join ManyAlbums as e
      on (e.UserId=d.UId Fk)
      left join Title as f
      on (f.AlbumId=e.Al bumId)
      left join Data as g
      on (g.TitleId=f.Id )[/code]

      Comment

      Working...