简体   繁体   中英

I am trying to import data from an access database using SQL SELECT method in VBA

I am trying to import data from an access database using SQL SELECT method in VBA. I have already imported the data from one table using SQL, this specific line worked for me. SQL = "Select * FROM grades" . The database has three tables grades, courses, and student. I am trying to import just the FirstName and LastName data from the student table and just the CourseName from the course table as all the rest of the data is already in the grades table. The grades and courses table both have coursecode which connects the Coursename in the courses table. Both the student and grade table have studentID which is connected to the first and last name in the student table. I am not sure how to write the SQl code in VBA order to get the coursename from the course table match the coursecode from the grades table and the student id from the grades table match the first and last name from the student table. Any help or leads?

' SQL = "SELECT *, courses.CourseName" & "FROM grades INNER JOIN courses" & "WHERE grades.CourseCode = grades.course"

this is my logic from what I found in the documentation but it doesnt seem to be working.

You should need something similar to this.

select g.*, c.CourseName, s.FirstName, s.LastName
from Grades g
inner join Students s
on s.StudentID = g.StudentID
inner join Courses c
on c.CourseCode = g.CourseCode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM