Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Can this SQL Query be Simplified?

Started 1 month, 1 week ago by RBkanso
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 ( ...
Site: REAL Software Forums  REAL Software Forums - site profile
Forum: Databases  Databases - forum profile
Total authors: 4 authors
Total thread posts: 10 posts
Thread activity: no new posts during last week
Domain info for: realsoftware.com

Other posts in this thread:

simonjohn replied 1 month, 1 week ago
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 ...

RBkanso replied 1 month, 1 week ago
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.

simonjohn replied 1 month, 1 week ago
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....

npalardy replied 1 month, 1 week ago
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....

RBkanso replied 1 month, 1 week ago
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 ...

simonjohn replied 1 month, 1 week ago
OK - I'm too confused now - maybe someone else can help - good luck.

dglass replied 1 month, 1 week ago
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 replied 1 month, 1 week ago
_________________ Simon Larkin QiSQL Database Solutions Website : http://www.qisql.com Mac 10.5.8, Imac 2.4ghz, 4gb, RB 2009 R4

simonjohn replied 1 month, 1 week ago
_________________ Simon Larkin QiSQL Database Solutions Website : http://www.qisql.com Mac 10.5.8, Imac 2.4ghz, 4gb, RB 2009 R4

 

Top contributing authors

Name
Posts
simonjohn
5
user's latest post:
Can this SQL Query be Simplified?
Published (2009-11-06 11:38:00)
_________________ Simon Larkin QiSQL Database Solutions Website : http://www.qisql.com Mac 10.5.8, Imac 2.4ghz, 4gb, RB 2009 R4
RBkanso
3
user's latest post:
Can this SQL Query be Simplified?
Published (2009-11-05 15:56:00)
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  ...
dglass
1
user's latest post:
Can this SQL Query be Simplified?
Published (2009-11-05 18:25:00)
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...
npalardy
1
user's latest post:
Can this SQL Query be Simplified?
Published (2009-11-05 14:45:00)
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...

Related threads on "REAL Software Forums":

Related threads on other sites:

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