简体   繁体   中英

many to many relationship sql

在此处输入图片说明

What can i add to these three tables to allow a "family" to have many students and a family to have many parents?

i am struggling to get my head around what i could add which would allow me to do this.

Thanks

You need to add a foreign key in student and parent that maps back to family_id, Remove parent_id and student_id in the Family table. If you need to find all member of family 22

select * from family f 
join parent p on f.family_id=p.family_id
join student s on s.family_id=f.family_id
where f.family_id=22

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM