MYSQL 兩個資料表如何設計關聯性查詢
SELECT sname FROM `class` JOIN `student` ON `class`.id = `student`.cid where `class`.cname = 'D4';
use a0005; drop TABLE class; drop TABLE student; create table class (id int(2) not null, cname varchar(10) not null, primary key(id)); insert into class values (1, 'C1'),(2, 'D3'),(3, 'D4'),(4, 'F1'),(5, 'A1'); create table student (id int(2) not null, cid int(2) not null, sname varchar(10) not null, primary key(id)); insert into student values ( 1, 2, 'max'),( 2, 4, 'marry'),( 3, 3, 'tom'),( 4, 2, 'fannr'),( 5, 3, 'max'),( 6, 1, 'max'),( 7, 5, 'fannr'),( 8, 1, 'jack');
熱門評論