I have the following four tables (simplified for this discussion): Code: CREATE TABLE Bracekts ( ID integer NOT NULL PRIMARY KEY, Name varchar) CREATE TABLE Stats ( BracektID integer NOT NULL, Score integer NOT NULL DEFAULT '0' ) CREATE TABLE Picks ( BracektID integer NOT NULL, TeamID integer NOT NULL DEFAULT '0', PickNo integer NOT NULL ) CREATE TABLE Teams ( ...
OK, firstly I don't quite understand your design, why do you have the tables Brackets AND Stats - there seems to be a one to one relationship here which is pointless. Maybe I'm missing something? The Left Join implies that some Brackets will not have Stats - ??? The Group By b.ID is not needed as there can only ever be one value for each Primary Key. If you were to join Brackets and Stats ...
simonjohn, thanks for the response. I simplified the design to best describe my SQL dilemma, but both tables are needed (a bracket can have multiple Stats). And, at this point, I can't use views. I am simply wondering if the SQL statement is the best solution given the table structure. Thanks.
Just to make sure I understand -does your database model look a bit like this?: If so, why do you need the sub select? Couldn't you just use: Code: select b.name as name, coalesce ( s.score, 'No Scores For This Guy (or whatever U want)!') as score, t.name as team_name from Brackets b, teams t , picks p left outer join stats s on b.id = s.BracketID where b.id = p....
Seems to me this has something to do with March Madness and how individuals may select a "bracket" Is that what this is for ? Each "bracket" is a set of choices of teams that are matched against each other and who that person thinks will be the winner. A person fills out EVERY winner from the initial match ups to come up with who they think will be the national champion See http://www....
simonjohn wrote: Just to make sure I understand -does your database model look a bit like this? simonjohn, yes the database is similar to the one pictured above. simonjohn wrote: If so, why do you need the sub select? Couldn't you just use: Code: select b.name as name, coalesce ( s.score, 'No Scores For This Guy (or whatever U want)!') as score, t.name as team_name ...
How about AND p.pickno IN (1,2,3,4,5,6,7,8,9,10) ? Code: select b.name as name, coalesce ( s.score, 'No Scores For This Guy (or whatever U want)!') as score, t.name as team_name from Brackets b, teams t , picks p left outer join stats s on b.id = s.BracketID where b.id = p.BracektID and p.teamid = t.id and p.pickno in ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,...
simonjohn wrote: Just to make sure I understand -does your database model look a bit like this? simonjohn, yes the database is similar to the one pictured above. simonjohn wrote: If so, why do you need the sub select? Couldn't you just use: Code: select b.name as name, coalesce ( s.score, 'No Scores For This Guy (or whatever U want)!') as score, t.name as team_name ...
How about AND p.pickno IN (1,2,3,4,5,6,7,8,9,10) ? Code: select b.name as name, coalesce ( s.score, 'No Scores For This Guy (or whatever U want)!') as score, t.name as team_name from Brackets b, teams t , picks p left outer join stats s on b.id = s.BracketID where b.id = p.BracektID and p.teamid = t.id and...
Seems to me this has something to do with March Madness and how individuals may select a "bracket" Is that what this is for ? Each "bracket" is a set of choices of teams that are matched against each other and who that person thinks will be the winner. A person fills out EVERY winner from the initial match ups to come up with who they think will be the national champion See...
SQL Tune: Hi,
I am facing one performance issues in my... SQL Tune: Hi,
I am facing one performance issues in my below sql query. This query running with in 11 sec but someti... http://bit.ly/3dXXxK about 13 hours ago from twitterfeed
Thread profile page for "Can this SQL Query be Simplified?" on http://www.realsoftware.com.
This report page is a snippet summary view from a single thread "Can this SQL Query be Simplified?", located on the Message Board at http://www.realsoftware.com.
This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity