Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
nottawayblue
Starting Member
2 Posts |
Posted - 2009-12-15 : 12:56:43
|
Attempting to eleminate duplicate records from a query of two many-to-many tables. Basic premise: My database tracks training requirements for our members. I have three basic relevant tables: Members, Positions, and Courses. The positions table covers the available positions, the courses table covers the available courses. Each member can fill multiple positions and each position can be filled by multiple members. Similarly, each position has multiple course requirements and each course is required for multiple positions. So I have two seperate tables to track these: JMemberANDPosition and JPositionCourseRequirements.JMemberANDPosition has fields: MemberID, PositionIDJPositionCourseRequirements has fields: PositionID, CourseIDThe problem is when I join the two tables (to show what courses a member need to take), the result has multiple completely duplicative records. I am working solely in Access here, so DISTINCTROW is in play, but isn't working. Sample DataJMemberANDPositionMember ID PositionID1 11 32 12 23 3...JPositionANDCoursePositionID CourseID1 21 31 52 1 2 32 63 43 5...Resulting JoinMemberID CourseID1 21 31 51 41 52 22 32 52 12 32 63 4... The rows in red being the duplicates.The current SQL is SELECT DISTINCTROW JMemberANDPosition.MemberID, JPositionANDCourse.CourseIDFROM JMemberANDPosition INNER JOIN JPositionANDCourse ON JMemberANDPosition.PositionID = JPositionANDCourse.PositionID; Don't so much care about using DISTINCTROW, just looking to avoid the duplication.Thanks. |
|
X002548
Not Just a Number
15586 Posts |
|
nottawayblue
Starting Member
2 Posts |
Posted - 2009-12-15 : 14:06:25
|
I promise that is the SQL, and it's a copy/paste job from when I designed the original DB (which I tweaked to make this one) a few years back for a similar purpose. Back then I was actually playing with code at least once or twice a week, so my instint is that it wasn't pulled form the QBE, but I can't be sure.The distinct worked, btw. My interpretation was that DITINCT would cut it down to only say one listing per member, or per course, but, hmm. Thanks. |
 |
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|