3

I am building a windows form C# app. and I use oleDb for linking access database to my app. the problem is, My access database has two tables (students,courseCodes) and one column of the "students" table(courseName) is linked to one in the "courseCode" table (the "courseCode" table contains course codes for example course code 1 is Static and I use code 1 in the "students" table for displaying Statics) now when I want to select column containing Statics using

"SELECT DISTINCT courseName FROM students";

I got the "1" instead "Statics" is there any way to retrieve "Statics" instead "1"?

0

1 Answer 1

4

I'd say your naming convention is misleading and confusing. The column should be courseIndex, not courseName.

Do a JOIN, of course (no pun intended). This query will return the distinct course names that a given student has signed up for.

select distinct courseCode.courseName
from student
join courseCode
on student.courseId = courseCode.id
where student.id = ?

Please adjust for your schema details.

Personally I think this is a poor design. A student can sign up for many courses, and a course can have many students. This is a many-to-many relationship. You need a join table; sounds like you only have a foreign key one-to-many relationship here.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much duffymo you're so right I'll consider this in my design thank you for your advice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.