php - How to create a view/table in my context in mysql? -
I want to create a view / table in mysql I now have two tables:
Make table teacher (id int (10) tap auto_increment, name varchar (50), primary key (id)); Refer to the table student (id int (10) null auto_interpret, name varchar (50), teacher_id int (10), primary key (id), foreign key (teacher_id), teacher discount ID (cascade);
Now, I want to get the teacher.name
and student.name
in the same column, and make the teacher Teacher_id
as parent_id
, student.id
as id
.
The new table structure should be:
table (parent_id, id, name); Edit :
The value of the "Name" column is either the name of the teacher or the name of the student.
Example:
parent_id id name 0 1 teacher 1 1 2 student 1 1 3 student 2 0 4 teachers 2 4 5 student 3
How do they do that? Thanks in advance;)
EDIT: Is there anyone who has to do it? I'm thinking ...
I'm not sure that I think you're getting a teacher. Name
and student.name
in the same column. I have assumed that you want to add them together as a string, for example "John Smith, Michael Jones".
Select Teacher Teacher as teacher.id parent_id, student.id AS Child_id, CONCAT (teacher.name, ',', student.name) Name by teacher, student WHERE teacher .id = student. Teacher_ID;
Now you can only make one teacher;
Comments
Post a Comment