Sql搜索,一对多的关系

时间:2017-04-27 09:00:38

标签: mysql sql

enter image description here

有没有办法通过sql搜索获取特定计算机的所有组件及其属性?

2 个答案:

答案 0 :(得分:4)

select manufacturer,price,imglink,cores,brand,clock_frequency 
from computer
inner join computer_has_comp on computer.computer_id=computer_has_comp.computer_computer_id 
inner join cpu on computer_has_comp.compid=cpu.compid

答案 1 :(得分:1)

如果我确定关系正确,这可能会有效..

SELECT computer.*, computer_has_comp.*, cpu.* FROM computer 
LEFT JOIN computer_has_comp ON computer.computer_id=computer_has_comp.computer_computer_id
LEFT JOIN cpu ON computer_has_comp.compid=cpu.compid