Connecting Tech Pros Worldwide Forums | Help | Site Map

complex querys help needed

Member
 
Join Date: Jan 2009
Location: USA
Posts: 118
#1: Sep 16 '09
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.


Expand|Select|Wrap|Line Numbers
  1. select 
  2. c.Bulletin as Bulletin,
  3. b.Title as Title,
  4. c.Date as Date,
  5. d.ProfileName as Name,
  6. g.Path as Path 
  7. from
  8. ManyTitle as a 
  9. left join Title as b
  10. on (a.TitleId=b.Id)
  11. left join Bulletin as c
  12. on (c.TitleId=a.TitleId),
  13. WebInfo as d
  14. left join ManyAlbums as e
  15.  on (e.UserId=d.UIdFk)
  16. left join Title as f
  17. on (f.AlbumId=e.AlbumId)
  18. left join Data as g
  19. on (g.TitleId=f.Id)
  20. where a.UserId=d.UIdFk
  21. and a.UserId = any ( select FriendId from Friends )
  22.  

MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 283
#2: Sep 16 '09

re: complex querys help needed


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

Steven
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#3: Sep 17 '09

re: complex querys help needed


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:
Expand|Select|Wrap|Line Numbers
  1. select 
  2.     c.Bulletin as Bulletin,
  3.     b.Title as Title,
  4.     c.Date as Date,
  5.     d.ProfileName as Name,
  6.     g.Path as Path 
  7. from ManyTitle as a 
  8. left join Title as b
  9.     on (a.TitleId=b.Id)
  10. left join Bulletin as c 
  11.     on (c.TitleId=a.TitleId)
  12. INNER JOIN WebInfo as d
  13.     on a.UserId=d.UIdFk
  14.     and a.UserId = any ( 
  15.         select FriendId from Friends 
  16.     )
  17. left join ManyAlbums as e
  18.     on (e.UserId=d.UIdFk)
  19. left join Title as f
  20.     on (f.AlbumId=e.AlbumId)
  21. left join Data as g
  22.     on (g.TitleId=f.Id)
Reply


Similar MySQL Database bytes