dow98764
2016-05-22 16:10
浏览 48
已采纳

如何从sql表中检索数据并将其插入另一个表中

I am developing a 'online students discussion platform' for a certain university, i want a student to post a question to only students belonging in the same faculty so that if ICT student posts a question, the system extracts all the students in ICT faculty from the students table, attaches them to the post and inserts them into the table receivers.

The system is extracting all students from the students table but it is inserting only one student in the table receivers.

TABLES:

-students(regno,name,faculty_code) PRIMARY KEY regn
-receivers(id, regno,message_id)

how to do it?

图片转代码服务由CSDN问答提供 功能建议

我正在为某所大学开发一个“在线学生讨论平台”,我希望学生发一个问题给 只有属于同一学院的学生,如果ICT学生发布问题,系统会从学生表中提取ICT教员中的所有学生,将他们附在帖子上并将其插入表格接收器。 \ n

系统从学生表中提取所有学生,但它只在表格接收器中插入一个学生。

表格:

   -students(regno,name,faculty_code)PRIMARY KEY regn 
-receivers(id,regno,message_id)
   
 
 

怎么做?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongtang5057 2016-05-22 18:57
    已采纳

    Instead of having a table for receivers, a better approach would be for you to have a "faculty_code" field in the "message" table which would be populated with the faculty_code of the poster. So for each student, extract messages where student.faculty_code is equal to message.faculty_code.

    That way a student only sees messages posted by students in the same faculty as him/her.

    点赞 打赏 评论

相关推荐 更多相似问题