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

如何从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?

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

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

表格: p>

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

怎么做? p> div>

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.