-1

I want a SQL query that retrieves columns from different tables in Visual Basic 2010.

I have four tables like this:

  1. tblTeacher consists of

    TID (pk)
    TName

  2. tblSubject consists of

    SID (pk)
    subName
    TID (fk)
    TMID (fk)

  3. tblTime consists of

    TMID (pk)
    TMValue

  4. tblLecture consists of

    LecID (pk)
    LecDate
    TID (fk)
    subID (fk)
    TMID (fk)

tblLecture is for registered Lectures. There is a one-to-many relationship between the tables, wheretblLecture is many. Now my question is:

I want a SQL query that retrieves the registered Lectures and returns columns LecID, LecDate, TName, subName, TMValue. I want to view the results in a DataGridView.

How can I call this SQL in my project please? (In my project, I use an Access database and SQL.)

4

1 回答 1

0

您必须将表连接在一起,如下所示:

SELECT LecID,LecDate,TName,subName,TMValue
FROM tblLecture l, tblTeacher t, tblSubject s, tblTime i
WHERE l.TID=t.TID
AND   l.subID=s.SID
AND   l.TMID=i.TMID

此外,我想知道您的 tblTime 表。你确定你需要它吗?

于 2013-10-11T17:13:14.403 回答