Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有两个表:“user”和“grade”
我的“用户”表如下所示:
id|username|password|email
我的“等级”表如下所示:
studentid|names|exam1|exam2|...
我想将用户表中的“id”列与成绩表中的“studentid”列进行比较。如果登录用户的 id 为 5,那么我需要从成绩表中提取带有“names,exam1,exam2”的 studentid 5,并以 html 格式显示。我该怎么做呢?
请帮忙。
尝试这个..
SELECT names, exam1, exam2 FROM grade g INNER JOIN user u ON u.id = g.studentid WHERE u.id = 5
你需要JOIN两张桌子,
JOIN
SELECT a.*, b.* FROM user a INNER JOIN grade b ON a.ID = b.StudentID WHERE a.ID = 5
要进一步了解有关联接的更多信息,请访问以下链接: