Database for Lottery Best Practice Design












1














I am starting design an database to hold lottery results for study, in my Country I can download all results in excel.



Since the excel is all in on spreadsheet, I willing do some normalization for import that data, my question is about if my design is right focusing in performance, and how to deal with Group By, I am not sure, but I think I am failing badly on last one.



My initial design is:



For The Results:



CREATE TABLE `Game_Results` (
`Id` int UNSIGNED NOT NULL,
`Date_Game` date NOT NULL,
`Ball_01` tinyint UNSIGNED NOT NULL,
`Ball_02` tinyint UNSIGNED NOT NULL,
`Ball_03` tinyint UNSIGNED NOT NULL,
`Ball_04` tinyint UNSIGNED NOT NULL,
`Ball_05` tinyint UNSIGNED NOT NULL,
`Ball_06` tinyint UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


For the Prize Data:



CREATE TABLE `Game_Prize` (
`Game_Id` int UNSIGNED NOT NULL,
`Total_Bets` decimal UNSIGNED NOT NULL,
`Winners` smallint UNSIGNED NOT NULL DEFAULT '0',
`Prize_Per_winner` decimal UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Location of Winners:



CREATE TABLE `Prize_Location` (
`Game_Id` int UNSIGNED NOT NULL,
`State_Prize` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`City_Prize` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


This design is based on desired webpage, lets say:



One div With Last result, so query will be:



SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06` FROM Game_Results WHERE Id IN (SELECT MAX(Id) FROM Game_Results)


And Current Id will be global in php / Javascript



Another div in same page with the info of prize, so query will be:



 SELECT `Total_Bets`, `Winners`,  `Prize_Per_winner` FROM Game_Prize Where Game_Id = Id (from php / javascript)


If the person click on Winners then an modal would open with location data.



This time I can do an SELECT on last table and list that, theres no problem till here.



But I will try build some custom filters, and then the problems come out, my filters would let people use the features:




  • Whats the Ball who come out mote times?

  • List ordered balls by how many time come out.

  • Whats the State where more people won?

  • How many people won in one specific city?

  • Etc..


And the problem with duplicate that come outs with the possibility of export the result in PDF or DOCX, I will search for any javascript plugin to convert JSON on those, at this point, I am willing remake same structure of original Excel (I know about JOINS), example:




GameID = 55, ... , State = A, City = A (1 Person)



, ... , State A, City = A (1 Person)



, ... , State A, City = A (1 Person)



GameID = 56, ... , State = C, City = H



GameID = 57, ... , , , (No Winners)




The original Excel have all in same line mescling the cells for same game. Before the equal symbol (GameID, State, City, etc...) are the first line of columns, after the equal symbol are the data on botton, so GameID is mescling on table, like GROUP BY.



So, how should I deal with the last table ('Prize_Location') since sometimes there 3 or 6 Winners?



I mean, sometime people from same city and state would won, in this case how to deal with this situation?



And offcourse, this is the best way to design this database?



PS.: Index, Primary Keys, etc... I will do after choose an optimal design. The focus would be performance since I would share this data on my blog, and allow people filter and query this data, in another words, I have no idea how many people should use it too at sametime.










share|improve this question
























  • My current generic comment re "better"/"best" etc: There's no such thing as "better"/"best" in engineering unless you define it. Also unfortunately all reasonable practical definitions require a ridiculous amount of experience with a ridiculous number of factors that interact with chaotic sensitivity to details. Make straightforward designs. When you demonstrate via measurement that a design and all alternatives you can think of have problems (whatever that means at the time), then ask a very specific question. Which should also define "better"/"best". meta.stackexchange.com/q/204461
    – philipxy
    Nov 12 at 3:44
















1














I am starting design an database to hold lottery results for study, in my Country I can download all results in excel.



Since the excel is all in on spreadsheet, I willing do some normalization for import that data, my question is about if my design is right focusing in performance, and how to deal with Group By, I am not sure, but I think I am failing badly on last one.



My initial design is:



For The Results:



CREATE TABLE `Game_Results` (
`Id` int UNSIGNED NOT NULL,
`Date_Game` date NOT NULL,
`Ball_01` tinyint UNSIGNED NOT NULL,
`Ball_02` tinyint UNSIGNED NOT NULL,
`Ball_03` tinyint UNSIGNED NOT NULL,
`Ball_04` tinyint UNSIGNED NOT NULL,
`Ball_05` tinyint UNSIGNED NOT NULL,
`Ball_06` tinyint UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


For the Prize Data:



CREATE TABLE `Game_Prize` (
`Game_Id` int UNSIGNED NOT NULL,
`Total_Bets` decimal UNSIGNED NOT NULL,
`Winners` smallint UNSIGNED NOT NULL DEFAULT '0',
`Prize_Per_winner` decimal UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Location of Winners:



CREATE TABLE `Prize_Location` (
`Game_Id` int UNSIGNED NOT NULL,
`State_Prize` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`City_Prize` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


This design is based on desired webpage, lets say:



One div With Last result, so query will be:



SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06` FROM Game_Results WHERE Id IN (SELECT MAX(Id) FROM Game_Results)


And Current Id will be global in php / Javascript



Another div in same page with the info of prize, so query will be:



 SELECT `Total_Bets`, `Winners`,  `Prize_Per_winner` FROM Game_Prize Where Game_Id = Id (from php / javascript)


If the person click on Winners then an modal would open with location data.



This time I can do an SELECT on last table and list that, theres no problem till here.



But I will try build some custom filters, and then the problems come out, my filters would let people use the features:




  • Whats the Ball who come out mote times?

  • List ordered balls by how many time come out.

  • Whats the State where more people won?

  • How many people won in one specific city?

  • Etc..


And the problem with duplicate that come outs with the possibility of export the result in PDF or DOCX, I will search for any javascript plugin to convert JSON on those, at this point, I am willing remake same structure of original Excel (I know about JOINS), example:




GameID = 55, ... , State = A, City = A (1 Person)



, ... , State A, City = A (1 Person)



, ... , State A, City = A (1 Person)



GameID = 56, ... , State = C, City = H



GameID = 57, ... , , , (No Winners)




The original Excel have all in same line mescling the cells for same game. Before the equal symbol (GameID, State, City, etc...) are the first line of columns, after the equal symbol are the data on botton, so GameID is mescling on table, like GROUP BY.



So, how should I deal with the last table ('Prize_Location') since sometimes there 3 or 6 Winners?



I mean, sometime people from same city and state would won, in this case how to deal with this situation?



And offcourse, this is the best way to design this database?



PS.: Index, Primary Keys, etc... I will do after choose an optimal design. The focus would be performance since I would share this data on my blog, and allow people filter and query this data, in another words, I have no idea how many people should use it too at sametime.










share|improve this question
























  • My current generic comment re "better"/"best" etc: There's no such thing as "better"/"best" in engineering unless you define it. Also unfortunately all reasonable practical definitions require a ridiculous amount of experience with a ridiculous number of factors that interact with chaotic sensitivity to details. Make straightforward designs. When you demonstrate via measurement that a design and all alternatives you can think of have problems (whatever that means at the time), then ask a very specific question. Which should also define "better"/"best". meta.stackexchange.com/q/204461
    – philipxy
    Nov 12 at 3:44














1












1








1







I am starting design an database to hold lottery results for study, in my Country I can download all results in excel.



Since the excel is all in on spreadsheet, I willing do some normalization for import that data, my question is about if my design is right focusing in performance, and how to deal with Group By, I am not sure, but I think I am failing badly on last one.



My initial design is:



For The Results:



CREATE TABLE `Game_Results` (
`Id` int UNSIGNED NOT NULL,
`Date_Game` date NOT NULL,
`Ball_01` tinyint UNSIGNED NOT NULL,
`Ball_02` tinyint UNSIGNED NOT NULL,
`Ball_03` tinyint UNSIGNED NOT NULL,
`Ball_04` tinyint UNSIGNED NOT NULL,
`Ball_05` tinyint UNSIGNED NOT NULL,
`Ball_06` tinyint UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


For the Prize Data:



CREATE TABLE `Game_Prize` (
`Game_Id` int UNSIGNED NOT NULL,
`Total_Bets` decimal UNSIGNED NOT NULL,
`Winners` smallint UNSIGNED NOT NULL DEFAULT '0',
`Prize_Per_winner` decimal UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Location of Winners:



CREATE TABLE `Prize_Location` (
`Game_Id` int UNSIGNED NOT NULL,
`State_Prize` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`City_Prize` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


This design is based on desired webpage, lets say:



One div With Last result, so query will be:



SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06` FROM Game_Results WHERE Id IN (SELECT MAX(Id) FROM Game_Results)


And Current Id will be global in php / Javascript



Another div in same page with the info of prize, so query will be:



 SELECT `Total_Bets`, `Winners`,  `Prize_Per_winner` FROM Game_Prize Where Game_Id = Id (from php / javascript)


If the person click on Winners then an modal would open with location data.



This time I can do an SELECT on last table and list that, theres no problem till here.



But I will try build some custom filters, and then the problems come out, my filters would let people use the features:




  • Whats the Ball who come out mote times?

  • List ordered balls by how many time come out.

  • Whats the State where more people won?

  • How many people won in one specific city?

  • Etc..


And the problem with duplicate that come outs with the possibility of export the result in PDF or DOCX, I will search for any javascript plugin to convert JSON on those, at this point, I am willing remake same structure of original Excel (I know about JOINS), example:




GameID = 55, ... , State = A, City = A (1 Person)



, ... , State A, City = A (1 Person)



, ... , State A, City = A (1 Person)



GameID = 56, ... , State = C, City = H



GameID = 57, ... , , , (No Winners)




The original Excel have all in same line mescling the cells for same game. Before the equal symbol (GameID, State, City, etc...) are the first line of columns, after the equal symbol are the data on botton, so GameID is mescling on table, like GROUP BY.



So, how should I deal with the last table ('Prize_Location') since sometimes there 3 or 6 Winners?



I mean, sometime people from same city and state would won, in this case how to deal with this situation?



And offcourse, this is the best way to design this database?



PS.: Index, Primary Keys, etc... I will do after choose an optimal design. The focus would be performance since I would share this data on my blog, and allow people filter and query this data, in another words, I have no idea how many people should use it too at sametime.










share|improve this question















I am starting design an database to hold lottery results for study, in my Country I can download all results in excel.



Since the excel is all in on spreadsheet, I willing do some normalization for import that data, my question is about if my design is right focusing in performance, and how to deal with Group By, I am not sure, but I think I am failing badly on last one.



My initial design is:



For The Results:



CREATE TABLE `Game_Results` (
`Id` int UNSIGNED NOT NULL,
`Date_Game` date NOT NULL,
`Ball_01` tinyint UNSIGNED NOT NULL,
`Ball_02` tinyint UNSIGNED NOT NULL,
`Ball_03` tinyint UNSIGNED NOT NULL,
`Ball_04` tinyint UNSIGNED NOT NULL,
`Ball_05` tinyint UNSIGNED NOT NULL,
`Ball_06` tinyint UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


For the Prize Data:



CREATE TABLE `Game_Prize` (
`Game_Id` int UNSIGNED NOT NULL,
`Total_Bets` decimal UNSIGNED NOT NULL,
`Winners` smallint UNSIGNED NOT NULL DEFAULT '0',
`Prize_Per_winner` decimal UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


Location of Winners:



CREATE TABLE `Prize_Location` (
`Game_Id` int UNSIGNED NOT NULL,
`State_Prize` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`City_Prize` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;


This design is based on desired webpage, lets say:



One div With Last result, so query will be:



SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06` FROM Game_Results WHERE Id IN (SELECT MAX(Id) FROM Game_Results)


And Current Id will be global in php / Javascript



Another div in same page with the info of prize, so query will be:



 SELECT `Total_Bets`, `Winners`,  `Prize_Per_winner` FROM Game_Prize Where Game_Id = Id (from php / javascript)


If the person click on Winners then an modal would open with location data.



This time I can do an SELECT on last table and list that, theres no problem till here.



But I will try build some custom filters, and then the problems come out, my filters would let people use the features:




  • Whats the Ball who come out mote times?

  • List ordered balls by how many time come out.

  • Whats the State where more people won?

  • How many people won in one specific city?

  • Etc..


And the problem with duplicate that come outs with the possibility of export the result in PDF or DOCX, I will search for any javascript plugin to convert JSON on those, at this point, I am willing remake same structure of original Excel (I know about JOINS), example:




GameID = 55, ... , State = A, City = A (1 Person)



, ... , State A, City = A (1 Person)



, ... , State A, City = A (1 Person)



GameID = 56, ... , State = C, City = H



GameID = 57, ... , , , (No Winners)




The original Excel have all in same line mescling the cells for same game. Before the equal symbol (GameID, State, City, etc...) are the first line of columns, after the equal symbol are the data on botton, so GameID is mescling on table, like GROUP BY.



So, how should I deal with the last table ('Prize_Location') since sometimes there 3 or 6 Winners?



I mean, sometime people from same city and state would won, in this case how to deal with this situation?



And offcourse, this is the best way to design this database?



PS.: Index, Primary Keys, etc... I will do after choose an optimal design. The focus would be performance since I would share this data on my blog, and allow people filter and query this data, in another words, I have no idea how many people should use it too at sametime.







database-design group-by mariadb normalization






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 2:30

























asked Nov 12 at 1:18









Wisdown

177




177












  • My current generic comment re "better"/"best" etc: There's no such thing as "better"/"best" in engineering unless you define it. Also unfortunately all reasonable practical definitions require a ridiculous amount of experience with a ridiculous number of factors that interact with chaotic sensitivity to details. Make straightforward designs. When you demonstrate via measurement that a design and all alternatives you can think of have problems (whatever that means at the time), then ask a very specific question. Which should also define "better"/"best". meta.stackexchange.com/q/204461
    – philipxy
    Nov 12 at 3:44


















  • My current generic comment re "better"/"best" etc: There's no such thing as "better"/"best" in engineering unless you define it. Also unfortunately all reasonable practical definitions require a ridiculous amount of experience with a ridiculous number of factors that interact with chaotic sensitivity to details. Make straightforward designs. When you demonstrate via measurement that a design and all alternatives you can think of have problems (whatever that means at the time), then ask a very specific question. Which should also define "better"/"best". meta.stackexchange.com/q/204461
    – philipxy
    Nov 12 at 3:44
















My current generic comment re "better"/"best" etc: There's no such thing as "better"/"best" in engineering unless you define it. Also unfortunately all reasonable practical definitions require a ridiculous amount of experience with a ridiculous number of factors that interact with chaotic sensitivity to details. Make straightforward designs. When you demonstrate via measurement that a design and all alternatives you can think of have problems (whatever that means at the time), then ask a very specific question. Which should also define "better"/"best". meta.stackexchange.com/q/204461
– philipxy
Nov 12 at 3:44




My current generic comment re "better"/"best" etc: There's no such thing as "better"/"best" in engineering unless you define it. Also unfortunately all reasonable practical definitions require a ridiculous amount of experience with a ridiculous number of factors that interact with chaotic sensitivity to details. Make straightforward designs. When you demonstrate via measurement that a design and all alternatives you can think of have problems (whatever that means at the time), then ask a very specific question. Which should also define "better"/"best". meta.stackexchange.com/q/204461
– philipxy
Nov 12 at 3:44












2 Answers
2






active

oldest

votes


















1














SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06`
FROM Game_Results WHERE Id IN (SELECT MAX(Id) FROM Game_Results)


is better done this way:



SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06`
FROM Game_Results ORDER BY Id DESC LIMIT 1


Be cautious about using a naked DECIMAL. Consider using some form of INT for whole numbers.



Are the balls ordered or not?



You should consider having 6 rows in a table dedicated to the balls instead of having 6 columns. This will simplify calculating stats on ball numbers.



I don't see much need for normalizing Locations. Just have these in the prize table:



state CHAR(2)     CHARACTER SET ascii,
city VARCHAR(40) CHARACTER SET ascii


(255 and utf8mb4 are unnecessary).



You can still discover multiple winners in a city via:



SELECT city, state, COUNT(*)
FROM prizes
GROUP BY city, state
HAVING COUNT(*) > 1





share|improve this answer





















  • Nice, your select shows better on query plan. And yes balls are ordered. Decimal is for the amount the lottery get from bets, usually some millions, example: 12.567.800,00. I have set Localization in an extra table thinking on website layout, since localization will be used only when visitor specify that on filter, or Clicking in Winners for check details, have that in an 3rd table for casual checks sounds need for performance, not sure if the best way. About the 6 collumns is because I will hold all results, would you give an example how is more easy using rows? With columns I use cursor.
    – Wisdown
    Nov 12 at 13:27












  • @Wisdown - DECIMAL implies DECIMAL(10,0). Are you OK with no decimal places? And exactly 10 to the left?
    – Rick James
    Nov 12 at 15:17










  • @Wisdown - "Cursor" has different meanings. Try to avoid them in Stored Procedures. As for the 6 columns vs another table with 6 rows -- Keep it in mind as you develop the SELECTs. Think through what it would take for each schema. Decide later.
    – Rick James
    Nov 12 at 15:19










  • Thanks for the Hints!!! I will do it on endweek, since this is a personal project as hobby. I would delimit the decimal is an nice tuning for save memory from server. For cursor I know they are an performance killer, but I have no Idea how to get same results without them. I mean, I know how to do the things with PHP and arrays, but without array on Database cursor is my lifesaver, hehehe. I set in one line thinking on indexing or better say using Id as PK on Game_results table, so I can force the use of index retrieving an single line per request / select.
    – Wisdown
    Nov 14 at 9:18












  • Example, SELECT * FROM Game_Results USE INDEX (PRIMARY) WHERE Id = "Something from current page, coming from PHP or AJAX from javascript"
    – Wisdown
    Nov 14 at 9:20



















1














One option might be to redefine the the Prize_Location table to allow a given Game_Id to be associated with the same location more than once. I suggest the following:



CREATE TABLE Prize_Location (
Game_Id int UNSIGNED NOT NULL,
Location_Id int NOT NULL
)

CREATE TABLE Locations (
Id int UNSIGNED NOT NULL,
State_Prize varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
City_Prize varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
)


Now in Prize_Location, a given Game_Id can appear associated with a given Location_Id more than once. This is how you would represent a given city and state happening to have more than one winner. You could also make Game_Id, Location_Id a primary key, and instead store a count, but that seems more cumbersome than just allowing multiple entries for a given game and location.






share|improve this answer





















  • I will update the original question with more details. I like your approach, but dindt get the use of table Locations. Example: 3 Winners From Same City (City A) and State (State A) will have an unique Id (lets say Id 14) on Locations (Cool) But on Prize Location I Will Have 3 times same data: Game_Id from a game with 6 winners: 3 of them will have Id 14. Gimme a sec for update main topic
    – Wisdown
    Nov 12 at 2:00










  • Yes, this is what I am suggesting. If this would not work for you, then state why.
    – Tim Biegeleisen
    Nov 12 at 2:01










  • Have updated the question with the goals of design, would you imagine another option? I think main problem will be on part export on PDF trying remake same format of excel, like new details in main question.
    – Wisdown
    Nov 12 at 2:16










  • I don't know what Excel has to do with a SQL design question. If you see any flaws in my suggestion, then feel free to point them out.
    – Tim Biegeleisen
    Nov 12 at 2:19










  • Using my design to retrieve all in one line for export in Excel / PDF / DOC / etc... I will need only 1 INNER JOIN, and 1 LEFT OUTER JOIN, using yours will have an extra JOIN (table Locations), example using the structure of main question: SELECT * FROM Game_Results GR INNER JOIN Game_Prize GP ON GR.Id = GP.Id LEFT OUTER JOIN Prize_Location PL ON GR.Id = PL.Game_Id. PS.: Offcourse I will format null fields of LEFT OUTER JOIN its just an example for explain how I need all data in one line to export.
    – Wisdown
    Nov 12 at 2:24













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254875%2fdatabase-for-lottery-best-practice-design%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06`
FROM Game_Results WHERE Id IN (SELECT MAX(Id) FROM Game_Results)


is better done this way:



SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06`
FROM Game_Results ORDER BY Id DESC LIMIT 1


Be cautious about using a naked DECIMAL. Consider using some form of INT for whole numbers.



Are the balls ordered or not?



You should consider having 6 rows in a table dedicated to the balls instead of having 6 columns. This will simplify calculating stats on ball numbers.



I don't see much need for normalizing Locations. Just have these in the prize table:



state CHAR(2)     CHARACTER SET ascii,
city VARCHAR(40) CHARACTER SET ascii


(255 and utf8mb4 are unnecessary).



You can still discover multiple winners in a city via:



SELECT city, state, COUNT(*)
FROM prizes
GROUP BY city, state
HAVING COUNT(*) > 1





share|improve this answer





















  • Nice, your select shows better on query plan. And yes balls are ordered. Decimal is for the amount the lottery get from bets, usually some millions, example: 12.567.800,00. I have set Localization in an extra table thinking on website layout, since localization will be used only when visitor specify that on filter, or Clicking in Winners for check details, have that in an 3rd table for casual checks sounds need for performance, not sure if the best way. About the 6 collumns is because I will hold all results, would you give an example how is more easy using rows? With columns I use cursor.
    – Wisdown
    Nov 12 at 13:27












  • @Wisdown - DECIMAL implies DECIMAL(10,0). Are you OK with no decimal places? And exactly 10 to the left?
    – Rick James
    Nov 12 at 15:17










  • @Wisdown - "Cursor" has different meanings. Try to avoid them in Stored Procedures. As for the 6 columns vs another table with 6 rows -- Keep it in mind as you develop the SELECTs. Think through what it would take for each schema. Decide later.
    – Rick James
    Nov 12 at 15:19










  • Thanks for the Hints!!! I will do it on endweek, since this is a personal project as hobby. I would delimit the decimal is an nice tuning for save memory from server. For cursor I know they are an performance killer, but I have no Idea how to get same results without them. I mean, I know how to do the things with PHP and arrays, but without array on Database cursor is my lifesaver, hehehe. I set in one line thinking on indexing or better say using Id as PK on Game_results table, so I can force the use of index retrieving an single line per request / select.
    – Wisdown
    Nov 14 at 9:18












  • Example, SELECT * FROM Game_Results USE INDEX (PRIMARY) WHERE Id = "Something from current page, coming from PHP or AJAX from javascript"
    – Wisdown
    Nov 14 at 9:20
















1














SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06`
FROM Game_Results WHERE Id IN (SELECT MAX(Id) FROM Game_Results)


is better done this way:



SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06`
FROM Game_Results ORDER BY Id DESC LIMIT 1


Be cautious about using a naked DECIMAL. Consider using some form of INT for whole numbers.



Are the balls ordered or not?



You should consider having 6 rows in a table dedicated to the balls instead of having 6 columns. This will simplify calculating stats on ball numbers.



I don't see much need for normalizing Locations. Just have these in the prize table:



state CHAR(2)     CHARACTER SET ascii,
city VARCHAR(40) CHARACTER SET ascii


(255 and utf8mb4 are unnecessary).



You can still discover multiple winners in a city via:



SELECT city, state, COUNT(*)
FROM prizes
GROUP BY city, state
HAVING COUNT(*) > 1





share|improve this answer





















  • Nice, your select shows better on query plan. And yes balls are ordered. Decimal is for the amount the lottery get from bets, usually some millions, example: 12.567.800,00. I have set Localization in an extra table thinking on website layout, since localization will be used only when visitor specify that on filter, or Clicking in Winners for check details, have that in an 3rd table for casual checks sounds need for performance, not sure if the best way. About the 6 collumns is because I will hold all results, would you give an example how is more easy using rows? With columns I use cursor.
    – Wisdown
    Nov 12 at 13:27












  • @Wisdown - DECIMAL implies DECIMAL(10,0). Are you OK with no decimal places? And exactly 10 to the left?
    – Rick James
    Nov 12 at 15:17










  • @Wisdown - "Cursor" has different meanings. Try to avoid them in Stored Procedures. As for the 6 columns vs another table with 6 rows -- Keep it in mind as you develop the SELECTs. Think through what it would take for each schema. Decide later.
    – Rick James
    Nov 12 at 15:19










  • Thanks for the Hints!!! I will do it on endweek, since this is a personal project as hobby. I would delimit the decimal is an nice tuning for save memory from server. For cursor I know they are an performance killer, but I have no Idea how to get same results without them. I mean, I know how to do the things with PHP and arrays, but without array on Database cursor is my lifesaver, hehehe. I set in one line thinking on indexing or better say using Id as PK on Game_results table, so I can force the use of index retrieving an single line per request / select.
    – Wisdown
    Nov 14 at 9:18












  • Example, SELECT * FROM Game_Results USE INDEX (PRIMARY) WHERE Id = "Something from current page, coming from PHP or AJAX from javascript"
    – Wisdown
    Nov 14 at 9:20














1












1








1






SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06`
FROM Game_Results WHERE Id IN (SELECT MAX(Id) FROM Game_Results)


is better done this way:



SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06`
FROM Game_Results ORDER BY Id DESC LIMIT 1


Be cautious about using a naked DECIMAL. Consider using some form of INT for whole numbers.



Are the balls ordered or not?



You should consider having 6 rows in a table dedicated to the balls instead of having 6 columns. This will simplify calculating stats on ball numbers.



I don't see much need for normalizing Locations. Just have these in the prize table:



state CHAR(2)     CHARACTER SET ascii,
city VARCHAR(40) CHARACTER SET ascii


(255 and utf8mb4 are unnecessary).



You can still discover multiple winners in a city via:



SELECT city, state, COUNT(*)
FROM prizes
GROUP BY city, state
HAVING COUNT(*) > 1





share|improve this answer












SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06`
FROM Game_Results WHERE Id IN (SELECT MAX(Id) FROM Game_Results)


is better done this way:



SELECT `Ball_01`, `Ball_02`, `Ball_03`, `Ball_04`, `Ball_05`, `Ball_06`
FROM Game_Results ORDER BY Id DESC LIMIT 1


Be cautious about using a naked DECIMAL. Consider using some form of INT for whole numbers.



Are the balls ordered or not?



You should consider having 6 rows in a table dedicated to the balls instead of having 6 columns. This will simplify calculating stats on ball numbers.



I don't see much need for normalizing Locations. Just have these in the prize table:



state CHAR(2)     CHARACTER SET ascii,
city VARCHAR(40) CHARACTER SET ascii


(255 and utf8mb4 are unnecessary).



You can still discover multiple winners in a city via:



SELECT city, state, COUNT(*)
FROM prizes
GROUP BY city, state
HAVING COUNT(*) > 1






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 3:36









Rick James

65.7k55797




65.7k55797












  • Nice, your select shows better on query plan. And yes balls are ordered. Decimal is for the amount the lottery get from bets, usually some millions, example: 12.567.800,00. I have set Localization in an extra table thinking on website layout, since localization will be used only when visitor specify that on filter, or Clicking in Winners for check details, have that in an 3rd table for casual checks sounds need for performance, not sure if the best way. About the 6 collumns is because I will hold all results, would you give an example how is more easy using rows? With columns I use cursor.
    – Wisdown
    Nov 12 at 13:27












  • @Wisdown - DECIMAL implies DECIMAL(10,0). Are you OK with no decimal places? And exactly 10 to the left?
    – Rick James
    Nov 12 at 15:17










  • @Wisdown - "Cursor" has different meanings. Try to avoid them in Stored Procedures. As for the 6 columns vs another table with 6 rows -- Keep it in mind as you develop the SELECTs. Think through what it would take for each schema. Decide later.
    – Rick James
    Nov 12 at 15:19










  • Thanks for the Hints!!! I will do it on endweek, since this is a personal project as hobby. I would delimit the decimal is an nice tuning for save memory from server. For cursor I know they are an performance killer, but I have no Idea how to get same results without them. I mean, I know how to do the things with PHP and arrays, but without array on Database cursor is my lifesaver, hehehe. I set in one line thinking on indexing or better say using Id as PK on Game_results table, so I can force the use of index retrieving an single line per request / select.
    – Wisdown
    Nov 14 at 9:18












  • Example, SELECT * FROM Game_Results USE INDEX (PRIMARY) WHERE Id = "Something from current page, coming from PHP or AJAX from javascript"
    – Wisdown
    Nov 14 at 9:20


















  • Nice, your select shows better on query plan. And yes balls are ordered. Decimal is for the amount the lottery get from bets, usually some millions, example: 12.567.800,00. I have set Localization in an extra table thinking on website layout, since localization will be used only when visitor specify that on filter, or Clicking in Winners for check details, have that in an 3rd table for casual checks sounds need for performance, not sure if the best way. About the 6 collumns is because I will hold all results, would you give an example how is more easy using rows? With columns I use cursor.
    – Wisdown
    Nov 12 at 13:27












  • @Wisdown - DECIMAL implies DECIMAL(10,0). Are you OK with no decimal places? And exactly 10 to the left?
    – Rick James
    Nov 12 at 15:17










  • @Wisdown - "Cursor" has different meanings. Try to avoid them in Stored Procedures. As for the 6 columns vs another table with 6 rows -- Keep it in mind as you develop the SELECTs. Think through what it would take for each schema. Decide later.
    – Rick James
    Nov 12 at 15:19










  • Thanks for the Hints!!! I will do it on endweek, since this is a personal project as hobby. I would delimit the decimal is an nice tuning for save memory from server. For cursor I know they are an performance killer, but I have no Idea how to get same results without them. I mean, I know how to do the things with PHP and arrays, but without array on Database cursor is my lifesaver, hehehe. I set in one line thinking on indexing or better say using Id as PK on Game_results table, so I can force the use of index retrieving an single line per request / select.
    – Wisdown
    Nov 14 at 9:18












  • Example, SELECT * FROM Game_Results USE INDEX (PRIMARY) WHERE Id = "Something from current page, coming from PHP or AJAX from javascript"
    – Wisdown
    Nov 14 at 9:20
















Nice, your select shows better on query plan. And yes balls are ordered. Decimal is for the amount the lottery get from bets, usually some millions, example: 12.567.800,00. I have set Localization in an extra table thinking on website layout, since localization will be used only when visitor specify that on filter, or Clicking in Winners for check details, have that in an 3rd table for casual checks sounds need for performance, not sure if the best way. About the 6 collumns is because I will hold all results, would you give an example how is more easy using rows? With columns I use cursor.
– Wisdown
Nov 12 at 13:27






Nice, your select shows better on query plan. And yes balls are ordered. Decimal is for the amount the lottery get from bets, usually some millions, example: 12.567.800,00. I have set Localization in an extra table thinking on website layout, since localization will be used only when visitor specify that on filter, or Clicking in Winners for check details, have that in an 3rd table for casual checks sounds need for performance, not sure if the best way. About the 6 collumns is because I will hold all results, would you give an example how is more easy using rows? With columns I use cursor.
– Wisdown
Nov 12 at 13:27














@Wisdown - DECIMAL implies DECIMAL(10,0). Are you OK with no decimal places? And exactly 10 to the left?
– Rick James
Nov 12 at 15:17




@Wisdown - DECIMAL implies DECIMAL(10,0). Are you OK with no decimal places? And exactly 10 to the left?
– Rick James
Nov 12 at 15:17












@Wisdown - "Cursor" has different meanings. Try to avoid them in Stored Procedures. As for the 6 columns vs another table with 6 rows -- Keep it in mind as you develop the SELECTs. Think through what it would take for each schema. Decide later.
– Rick James
Nov 12 at 15:19




@Wisdown - "Cursor" has different meanings. Try to avoid them in Stored Procedures. As for the 6 columns vs another table with 6 rows -- Keep it in mind as you develop the SELECTs. Think through what it would take for each schema. Decide later.
– Rick James
Nov 12 at 15:19












Thanks for the Hints!!! I will do it on endweek, since this is a personal project as hobby. I would delimit the decimal is an nice tuning for save memory from server. For cursor I know they are an performance killer, but I have no Idea how to get same results without them. I mean, I know how to do the things with PHP and arrays, but without array on Database cursor is my lifesaver, hehehe. I set in one line thinking on indexing or better say using Id as PK on Game_results table, so I can force the use of index retrieving an single line per request / select.
– Wisdown
Nov 14 at 9:18






Thanks for the Hints!!! I will do it on endweek, since this is a personal project as hobby. I would delimit the decimal is an nice tuning for save memory from server. For cursor I know they are an performance killer, but I have no Idea how to get same results without them. I mean, I know how to do the things with PHP and arrays, but without array on Database cursor is my lifesaver, hehehe. I set in one line thinking on indexing or better say using Id as PK on Game_results table, so I can force the use of index retrieving an single line per request / select.
– Wisdown
Nov 14 at 9:18














Example, SELECT * FROM Game_Results USE INDEX (PRIMARY) WHERE Id = "Something from current page, coming from PHP or AJAX from javascript"
– Wisdown
Nov 14 at 9:20




Example, SELECT * FROM Game_Results USE INDEX (PRIMARY) WHERE Id = "Something from current page, coming from PHP or AJAX from javascript"
– Wisdown
Nov 14 at 9:20













1














One option might be to redefine the the Prize_Location table to allow a given Game_Id to be associated with the same location more than once. I suggest the following:



CREATE TABLE Prize_Location (
Game_Id int UNSIGNED NOT NULL,
Location_Id int NOT NULL
)

CREATE TABLE Locations (
Id int UNSIGNED NOT NULL,
State_Prize varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
City_Prize varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
)


Now in Prize_Location, a given Game_Id can appear associated with a given Location_Id more than once. This is how you would represent a given city and state happening to have more than one winner. You could also make Game_Id, Location_Id a primary key, and instead store a count, but that seems more cumbersome than just allowing multiple entries for a given game and location.






share|improve this answer





















  • I will update the original question with more details. I like your approach, but dindt get the use of table Locations. Example: 3 Winners From Same City (City A) and State (State A) will have an unique Id (lets say Id 14) on Locations (Cool) But on Prize Location I Will Have 3 times same data: Game_Id from a game with 6 winners: 3 of them will have Id 14. Gimme a sec for update main topic
    – Wisdown
    Nov 12 at 2:00










  • Yes, this is what I am suggesting. If this would not work for you, then state why.
    – Tim Biegeleisen
    Nov 12 at 2:01










  • Have updated the question with the goals of design, would you imagine another option? I think main problem will be on part export on PDF trying remake same format of excel, like new details in main question.
    – Wisdown
    Nov 12 at 2:16










  • I don't know what Excel has to do with a SQL design question. If you see any flaws in my suggestion, then feel free to point them out.
    – Tim Biegeleisen
    Nov 12 at 2:19










  • Using my design to retrieve all in one line for export in Excel / PDF / DOC / etc... I will need only 1 INNER JOIN, and 1 LEFT OUTER JOIN, using yours will have an extra JOIN (table Locations), example using the structure of main question: SELECT * FROM Game_Results GR INNER JOIN Game_Prize GP ON GR.Id = GP.Id LEFT OUTER JOIN Prize_Location PL ON GR.Id = PL.Game_Id. PS.: Offcourse I will format null fields of LEFT OUTER JOIN its just an example for explain how I need all data in one line to export.
    – Wisdown
    Nov 12 at 2:24


















1














One option might be to redefine the the Prize_Location table to allow a given Game_Id to be associated with the same location more than once. I suggest the following:



CREATE TABLE Prize_Location (
Game_Id int UNSIGNED NOT NULL,
Location_Id int NOT NULL
)

CREATE TABLE Locations (
Id int UNSIGNED NOT NULL,
State_Prize varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
City_Prize varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
)


Now in Prize_Location, a given Game_Id can appear associated with a given Location_Id more than once. This is how you would represent a given city and state happening to have more than one winner. You could also make Game_Id, Location_Id a primary key, and instead store a count, but that seems more cumbersome than just allowing multiple entries for a given game and location.






share|improve this answer





















  • I will update the original question with more details. I like your approach, but dindt get the use of table Locations. Example: 3 Winners From Same City (City A) and State (State A) will have an unique Id (lets say Id 14) on Locations (Cool) But on Prize Location I Will Have 3 times same data: Game_Id from a game with 6 winners: 3 of them will have Id 14. Gimme a sec for update main topic
    – Wisdown
    Nov 12 at 2:00










  • Yes, this is what I am suggesting. If this would not work for you, then state why.
    – Tim Biegeleisen
    Nov 12 at 2:01










  • Have updated the question with the goals of design, would you imagine another option? I think main problem will be on part export on PDF trying remake same format of excel, like new details in main question.
    – Wisdown
    Nov 12 at 2:16










  • I don't know what Excel has to do with a SQL design question. If you see any flaws in my suggestion, then feel free to point them out.
    – Tim Biegeleisen
    Nov 12 at 2:19










  • Using my design to retrieve all in one line for export in Excel / PDF / DOC / etc... I will need only 1 INNER JOIN, and 1 LEFT OUTER JOIN, using yours will have an extra JOIN (table Locations), example using the structure of main question: SELECT * FROM Game_Results GR INNER JOIN Game_Prize GP ON GR.Id = GP.Id LEFT OUTER JOIN Prize_Location PL ON GR.Id = PL.Game_Id. PS.: Offcourse I will format null fields of LEFT OUTER JOIN its just an example for explain how I need all data in one line to export.
    – Wisdown
    Nov 12 at 2:24
















1












1








1






One option might be to redefine the the Prize_Location table to allow a given Game_Id to be associated with the same location more than once. I suggest the following:



CREATE TABLE Prize_Location (
Game_Id int UNSIGNED NOT NULL,
Location_Id int NOT NULL
)

CREATE TABLE Locations (
Id int UNSIGNED NOT NULL,
State_Prize varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
City_Prize varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
)


Now in Prize_Location, a given Game_Id can appear associated with a given Location_Id more than once. This is how you would represent a given city and state happening to have more than one winner. You could also make Game_Id, Location_Id a primary key, and instead store a count, but that seems more cumbersome than just allowing multiple entries for a given game and location.






share|improve this answer












One option might be to redefine the the Prize_Location table to allow a given Game_Id to be associated with the same location more than once. I suggest the following:



CREATE TABLE Prize_Location (
Game_Id int UNSIGNED NOT NULL,
Location_Id int NOT NULL
)

CREATE TABLE Locations (
Id int UNSIGNED NOT NULL,
State_Prize varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
City_Prize varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
)


Now in Prize_Location, a given Game_Id can appear associated with a given Location_Id more than once. This is how you would represent a given city and state happening to have more than one winner. You could also make Game_Id, Location_Id a primary key, and instead store a count, but that seems more cumbersome than just allowing multiple entries for a given game and location.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 1:27









Tim Biegeleisen

215k1386137




215k1386137












  • I will update the original question with more details. I like your approach, but dindt get the use of table Locations. Example: 3 Winners From Same City (City A) and State (State A) will have an unique Id (lets say Id 14) on Locations (Cool) But on Prize Location I Will Have 3 times same data: Game_Id from a game with 6 winners: 3 of them will have Id 14. Gimme a sec for update main topic
    – Wisdown
    Nov 12 at 2:00










  • Yes, this is what I am suggesting. If this would not work for you, then state why.
    – Tim Biegeleisen
    Nov 12 at 2:01










  • Have updated the question with the goals of design, would you imagine another option? I think main problem will be on part export on PDF trying remake same format of excel, like new details in main question.
    – Wisdown
    Nov 12 at 2:16










  • I don't know what Excel has to do with a SQL design question. If you see any flaws in my suggestion, then feel free to point them out.
    – Tim Biegeleisen
    Nov 12 at 2:19










  • Using my design to retrieve all in one line for export in Excel / PDF / DOC / etc... I will need only 1 INNER JOIN, and 1 LEFT OUTER JOIN, using yours will have an extra JOIN (table Locations), example using the structure of main question: SELECT * FROM Game_Results GR INNER JOIN Game_Prize GP ON GR.Id = GP.Id LEFT OUTER JOIN Prize_Location PL ON GR.Id = PL.Game_Id. PS.: Offcourse I will format null fields of LEFT OUTER JOIN its just an example for explain how I need all data in one line to export.
    – Wisdown
    Nov 12 at 2:24




















  • I will update the original question with more details. I like your approach, but dindt get the use of table Locations. Example: 3 Winners From Same City (City A) and State (State A) will have an unique Id (lets say Id 14) on Locations (Cool) But on Prize Location I Will Have 3 times same data: Game_Id from a game with 6 winners: 3 of them will have Id 14. Gimme a sec for update main topic
    – Wisdown
    Nov 12 at 2:00










  • Yes, this is what I am suggesting. If this would not work for you, then state why.
    – Tim Biegeleisen
    Nov 12 at 2:01










  • Have updated the question with the goals of design, would you imagine another option? I think main problem will be on part export on PDF trying remake same format of excel, like new details in main question.
    – Wisdown
    Nov 12 at 2:16










  • I don't know what Excel has to do with a SQL design question. If you see any flaws in my suggestion, then feel free to point them out.
    – Tim Biegeleisen
    Nov 12 at 2:19










  • Using my design to retrieve all in one line for export in Excel / PDF / DOC / etc... I will need only 1 INNER JOIN, and 1 LEFT OUTER JOIN, using yours will have an extra JOIN (table Locations), example using the structure of main question: SELECT * FROM Game_Results GR INNER JOIN Game_Prize GP ON GR.Id = GP.Id LEFT OUTER JOIN Prize_Location PL ON GR.Id = PL.Game_Id. PS.: Offcourse I will format null fields of LEFT OUTER JOIN its just an example for explain how I need all data in one line to export.
    – Wisdown
    Nov 12 at 2:24


















I will update the original question with more details. I like your approach, but dindt get the use of table Locations. Example: 3 Winners From Same City (City A) and State (State A) will have an unique Id (lets say Id 14) on Locations (Cool) But on Prize Location I Will Have 3 times same data: Game_Id from a game with 6 winners: 3 of them will have Id 14. Gimme a sec for update main topic
– Wisdown
Nov 12 at 2:00




I will update the original question with more details. I like your approach, but dindt get the use of table Locations. Example: 3 Winners From Same City (City A) and State (State A) will have an unique Id (lets say Id 14) on Locations (Cool) But on Prize Location I Will Have 3 times same data: Game_Id from a game with 6 winners: 3 of them will have Id 14. Gimme a sec for update main topic
– Wisdown
Nov 12 at 2:00












Yes, this is what I am suggesting. If this would not work for you, then state why.
– Tim Biegeleisen
Nov 12 at 2:01




Yes, this is what I am suggesting. If this would not work for you, then state why.
– Tim Biegeleisen
Nov 12 at 2:01












Have updated the question with the goals of design, would you imagine another option? I think main problem will be on part export on PDF trying remake same format of excel, like new details in main question.
– Wisdown
Nov 12 at 2:16




Have updated the question with the goals of design, would you imagine another option? I think main problem will be on part export on PDF trying remake same format of excel, like new details in main question.
– Wisdown
Nov 12 at 2:16












I don't know what Excel has to do with a SQL design question. If you see any flaws in my suggestion, then feel free to point them out.
– Tim Biegeleisen
Nov 12 at 2:19




I don't know what Excel has to do with a SQL design question. If you see any flaws in my suggestion, then feel free to point them out.
– Tim Biegeleisen
Nov 12 at 2:19












Using my design to retrieve all in one line for export in Excel / PDF / DOC / etc... I will need only 1 INNER JOIN, and 1 LEFT OUTER JOIN, using yours will have an extra JOIN (table Locations), example using the structure of main question: SELECT * FROM Game_Results GR INNER JOIN Game_Prize GP ON GR.Id = GP.Id LEFT OUTER JOIN Prize_Location PL ON GR.Id = PL.Game_Id. PS.: Offcourse I will format null fields of LEFT OUTER JOIN its just an example for explain how I need all data in one line to export.
– Wisdown
Nov 12 at 2:24






Using my design to retrieve all in one line for export in Excel / PDF / DOC / etc... I will need only 1 INNER JOIN, and 1 LEFT OUTER JOIN, using yours will have an extra JOIN (table Locations), example using the structure of main question: SELECT * FROM Game_Results GR INNER JOIN Game_Prize GP ON GR.Id = GP.Id LEFT OUTER JOIN Prize_Location PL ON GR.Id = PL.Game_Id. PS.: Offcourse I will format null fields of LEFT OUTER JOIN its just an example for explain how I need all data in one line to export.
– Wisdown
Nov 12 at 2:24




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254875%2fdatabase-for-lottery-best-practice-design%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values