我在我的mysql數據庫中有3個表:student, progress and subject
。當我嘗試選擇數據:如何鏈接表mysql
SELECT progress.id, progress.mark, subject.pname FROM progress, subject WHERE progress.id_student = 1;
下表我得到:
id mark pname
1 5 Math
1 5 Physics
表進步我只有一個條目:
id mark id_student id_subject
1 5 1 1
我怎樣才能通過student_id
得到學生的進步?
CREATE DATABASE students;
USE students;
CREATE TABLE student (
id int NOT NULL AUTO_INCREMENT,
name varchar(100) NOT NULL,
address varchar(60) NOT NULL,
byear int NOT NULL,
eyear int NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE subject (
id int NOT NULL AUTO_INCREMENT,
pname varchar(20) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE progress (
id int NOT NULL AUTO_INCREMENT,
mark int NOT NULL,
id_student int NOT NULL,
id_subject int NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (id) REFERENCES student (id),
FOREIGN KEY (id) REFERENCES subject (id)
);
你已經得到output.So什麼問題 – PSR