PDA

View Full Version : help with large Query and Join


angst
11-28-2005, 09:53 PM
hello,
I'm not really new with sql, but new with such large statements and joining tables.

my query:

select ldu.LeagueDataUserID, ldu.LeagueDataID, ldu.PriceTypeID, ldu.TeamBuilt, ldu.UserID, ldu.Year, ldu.TeamSeasonID, ldu.RequestedPlayers, t.Name as Team, ld.SeasonID, ld.LeagueID, ld.DayID, ld.SkillID, s.Name as Season, sk.Name as Skill, d.Name as Day, pt.Name as PriceType, l.Name as League, sc.Date as Date, u.FirstName, u.LastName, u.Username, u.Male, u.Email from csc_LeagueDataUser ldu left outer join csc_TeamSeason ts on ldu.TeamSeasonID = ts.TeamSeasonID left outer join csc_Team t on ts.TeamID = t.TeamID inner join csc_LeagueData ld on ldu.LeagueDataID = ld.LeagueDataID left outer join csc_Season s on ld.SeasonID = s.SeasonID left outer join csc_Skill sk on ld.SkillID = sk.SkillID left outer join csc_Day d on ld.DayID = d.DayID left outer join csc_PriceType pt on ldu.PriceTypeID = pt.PriceTypeID inner join csc_League l on ld.LeagueID = l.LeagueID inner join csc_User u on ldu.UserID = u.UserID inner join csc_ShoppingCart sc on ldu.UserID = sc.UserID where ldu.PriceTypeID = '1' and ldu.Deleted = '0'


the one I'm having trouble with is:
inner join csc_ShoppingCart sc on ldu.UserID = sc.UserID

it's just not returning anything at all, but i know there is data there.
can anyone please tell me what i'm doing wrong here? i'm really stuck on this one.

thanks in advance for your time!
-Ken

vinyl-junkie
11-29-2005, 01:36 AM
One thing that might help is formatting your statement to make it easier to read, like this:

select ldu.LeagueDataUserID
, ldu.LeagueDataID
, ldu.PriceTypeID
, ldu.TeamBuilt
, ldu.UserID
, ldu.Year
, ldu.TeamSeasonID
, ldu.RequestedPlayers
, t.Name as Team
, ld.SeasonID
, ld.LeagueID
, ld.DayID
, ld.SkillID
, s.Name as Season
, sk.Name as Skill
, d.Name as Day
, pt.Name as PriceType
, l.Name as League
, sc.Date as Date
, u.FirstName
, u.LastName
, u.Username
, u.Male
, u.Email
from csc_LeagueDataUser ldu
left outer join csc_TeamSeason ts
on ldu.TeamSeasonID = ts.TeamSeasonID
left outer join csc_Team t
on ts.TeamID = t.TeamID
inner join csc_LeagueData ld
on ldu.LeagueDataID = ld.LeagueDataID
left outer join csc_Season s
on ld.SeasonID = s.SeasonID
left outer join csc_Skill sk
on ld.SkillID = sk.SkillID
left outer join csc_Day d
on ld.DayID = d.DayID
left outer join csc_PriceType pt
on ldu.PriceTypeID = pt.PriceTypeID
inner join csc_League l
on ld.LeagueID = l.LeagueID
inner join csc_User u
on ldu.UserID = u.UserID
inner join csc_ShoppingCart sc
on ldu.UserID = sc.UserID
where
ldu.PriceTypeID = '1'
and
ldu.Deleted = '0'
Next, try running your query with just that one join you mentioned in it and examining the results. Do you have at least one record that meets the where condition? If so, add another one of your joins into the query and try it again. Keep doing that one at a time until you've narrowed down which join is causing you not to retrieve any records.

angst
11-29-2005, 04:01 PM
hmm, well I can't realy format the query because it i generated dynamicly.

also every part of the query works cept for:
"inner join csc_ShoppingCart sc on ldu.UserID = sc.UserID"

so just trying to figure out this one part.

thanks again for your time,
-Ken