Selecting a column from ms-access database that has related tables

I am creating a C # Windows Form Application. and I am using oleDb to bind an access database to my application. the problem is my access database has two tables (students, course courses) and one column "students" (course name) is linked to one in the "courseCode" table (the "CourseCode" table contains course codes, for example course code 1 is Static and I am using code 1 in the "students" table to display Statics) now when I want to select the column containing Statics using

"SELECT DISTINCT courseName FROM students";

      

I got "1" instead of "Static", is there a way to restore "Static" instead of "1"?

+3


source to share


1 answer


I would say that your naming convention is misleading and confusing. The column must be the cursorIndex, not the name of the course.

Make a JOIN of course (no pun intended). This query will return the individual course names for which this student is registered.

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

      



Please adjust these circuits.

Personally, I think this is bad design. A student can register for many courses and a course can have many students. This is a many-to-many relationship. You need a join table; it looks like you only have a one-to-many relationship from a foreign key.

+4


source







All Articles