March 14, 2007 at 11:54 pm
All,
I have a student class denormalized table where student and the courses he is registered to are being saved. There is a dummy cource where all the students
enrolled are initially assigned to. As students gets enrolled into different courses that records will get added in also. Again when a student registeres he
is enrolled into the dummy course.
eg
student course
-----------------
tom dummy
jerry dummy
tom math
tom english
tom biology
jerry math
harry dummy
Any help is greatly appreciated
March 15, 2007 at 12:04 am
What's your question?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 15, 2007 at 8:12 am
Hah... I forgot to post what the question was..
I need to write a query to find out the dummy rows if they exist in the table. (I donot know the value of the dummy row). ?
March 15, 2007 at 10:14 am
What distinguishes a dummy course from a real one?
I can give you a query that will find students with a single course, but if they have multiple, there will have to be a way to tell the dummy and real apart.
Unless you have a datestamp of some form there's no way to tell what row was inserted first.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 15, 2007 at 11:23 am
Thanks for the reply. The distinguishing feature of the dummy course is that all the students in the system will be assigned to that dummy row.
March 16, 2007 at 12:21 am
There's nothing else? Foreign key? Flag anywhere?
It's doable, but it's not going to be a nice query. Let me see what I can come up with....
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 16, 2007 at 2:25 am
Try this. It's not tested, but should work. It depends on the dummy course been the only one that all students take.
SELECT
* FROM courses WHERE course = (
SELECT course FROM courses GROUP BY courses
HAVING COUNT(*) = (SELECT COUNT(DISTINCT student) FROM courses)
)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 16, 2007 at 5:25 am
Maybe this?
SELECT TOP 1 Course
FROM Courses
GROUP BY Course
ORDER BY COUNT(*) DESC
N 56°04'39.16"
E 12°55'05.25"
March 16, 2007 at 7:04 am
Thanks guys. Appreciate your help.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply