Click here to Skip to main content
16,005,389 members

Comments by Franklin Smith (Top 9 by date)

Franklin Smith 17-Oct-12 3:07am View    
After a student logs in, they choose a course to study. The way things come down the line from there is.

Table 1 - CourseID
Table 2 - CourseID,ChapterID
Table 3 - ChapterID,AssessmentID(There can be multiple assessments per chapter not all will be vocab.)
Table 4 - GroupID(AssessmentID), WordID, Word, Description(Maybe better name would have been Definition)
Table 5 - WordID, SimilarWordID

That third table(Table_3) is a generated table that is being returned to a webpage. It doesn't actually exist. This selection of the exclusions is also not the normal. I just need it for the administration section to have a listbox that shows the words not currently linked to WordId.

I went back to check and I have setup Table 4 so that WordId is the Primary Key/Index and the GroupID is indexed. I'm thinking I should remove the indexing on WordId as it seems to me that what I want indexed together would be the GroupID records. I normally would worry about efficiency because in the past most of the stuff I put together was simple one or two concurrent user stuff. But on the student side I will end up with 3-4 hundred concurrent users.

But with regards to the Query would it be better to(I removed description as it is not needed for this Query)

SELECT Id, Word
FROM (SELECT Id, Word FROM Table_1 WHERE GroupID = @GroupID) AS Group
WHERE Group.Id <> @ExcludedItem
AND Group.Id NOT IN (SELECT SimilarWordID FROM Table_2 WHERE WordId = @ExcludedItem) AND Group.Id NOT IN (SELECT WordId FROM Table_2 WHERE SimilarWordID = @ExcludedItem)

Would that be more efficient?
Franklin Smith 16-Oct-12 9:49am View    
The GroupID is actually what I have as a AssessmentID in another table. The "Words" here are vocabulary words for a particular subject and chapter. Because of this in the stored proc I am Selecting A Group of words first into a temp table. But after seeing how you used the view I think I'd rather use them. I used the temp tables because I saw someone elses code use them, but I really hate dealing with the drop statements and IF exist Drop statements cause it is just more overhead. So I'm going to remove those in favor of the views.

So I'm thinking to solve the GroupID problem I need to do the following.
SELECT Id, Word, Description
FROM Table_1
--Changed line here
WHERE GroupID = @GroupID
AND Id <> @ExcludedItem
AND Id NOT IN (SELECT SimilarWordID FROM Table_2 WHERE WordId = @ExcludedItem)
AND Id NOT IN (SELECT WordId FROM Table_2 WHERE SimilarWordID = @ExcludedItem)
Franklin Smith 16-Oct-12 3:18am View    
Very elegant way of solving the problem. I'm going to have to see if I can implement that into my stored procedure. It would save me the temp tables. However, I'm not sure because one thing I found out I'm going to have to do. I have to add a column in the out table that specifies whether the WordID was found in the WordID Column or the SimilarWordID, but that is a matter for the included side not the exclusion.

One thing I'd like to ask though is, the data that this applies to is actually a subset. The table actually has something like GroupID, Id, Word, Description for columns. I'm just assuming here but to add the GroupID to this I'd need to add a "@GroupID int" to the parameters and in the SELECT's WHERE clause add "GroupID = @GroupID AND"
Franklin Smith 16-Oct-12 3:01am View    
I found the excluded ones by finding the included ones. It just happens that's how the code worked. I worked on this all day finding the bits and pieces I was missing. It was by no means simple. I just posted what I finally worked out. I like what you posted better as it's more elegant than what I put up.
Franklin Smith 15-Oct-12 14:20pm View    
This would almost work accept the Orange can not be hard coded and because these are going to put into Stored Procedures I needed similar coding that works both ways. So I came up what you will see below. But I still am having a problem with the one that gives me the results for those that aren't being used.