Following is my database with 4 tables(Student, Course, Module, Instructor). And I wan to know whether this database is correct or not and if I am doing right how can I retrieve data from tables using student id as below.
- What are the modules student 10122342 has? >>Expected answer: cn103, cn201
(pk) = primary key and (fk)=foreign key
The next thing is I wan to import some values from t开发者_运维百科hose above tables to a newly created table? the situation is I wan to import 's_id' and 'i_id' from above tables in 'id' attribute of newly crated table named "Everyone"; at the same time I also want to generate '0'/'1' value for 'type' attribute of "Everyone" table where 0 value for those id which are imported from 's_id' and 1 for rest of the ids imported from 'i_id'. Following is my expected new database table.
Everyone
id |type |
-----------------
10122345 | 0 |
10122342 | 0 |
10222346 | 0 |
20432343 | 1 |
20432311 | 1 |
20532334 | 1 |
Please Can anyone help me? is it possible to do with mysql and php? THanks.
This should be the answer to your first question:
SELECT m_code FROM Module a INNER JOIN Student b ON a.c_code = b.c_code WHERE b.s_id = '10122342'
I can't come up with the answer to your second question, though it should be something with joins, this might help: MySQL Insert & Joins
精彩评论