建資料庫students (建立三個** 分別儲存學生,教師,課程資訊)
mysql->create table student
->(
->key_student int(5) not null auto_increment, student_name varchar(20) not null,primary key (key_student)
->);
mysql->create table teacher
->(key_teacher int(5) not null auto_increment,teacher_name varhcar(20) not null,primary key (key_teacher)
->);
mysql->create table course ( key_course int(5) not null auto_increment,key_student int(5) not null,key_teacher int(5) not null,course_name varchar(20) not null,primary key (key_course)
->);
向三個**新增資料
mysql->insert into student (student_name) values (『tom』);
mysql->insert into student (student_name) values (『mary』);
mysql->insert into student (student_name) values (『bob』);
mysql->insert into teacher (teacher_name) values (『thomas yang』);
mysql->insert into teacher (teacher_name) values (『jonna farmer』);
mysql->insert into teacher (teacher_name) values (『christ miller』);
mysql->insert into course (course_name,key_student,key_teacher) values (『mathematics』,2,1);
mysql->insert into course (course_name,key_student,key_teacher) values (『physics』,1,3);
mysql->insert into course (course_name,key_student,key_teacher) values (『physics』,4,2);
insert into course (course_name,key_student,key_teacher) values (『biology』,3,4);
通過表的關聯來查詢資訊,例:列出所有課程的任課教師及選修該課的學生:
mysql->select course.course_name,teacher.teacher_name,student.student_namefrom course,teacher,student where course.key_student=student.key_student and course.key_teacher=teacher.key_teacher;
可以把上表通過關聯生成的虛擬表,虛擬表通過where子句將三個不同的**連線在一起
mysql->select
->course.course_name, teacher.teacher_name
->from course,teacher;
mysql->select
->course.course_name, teacher.teacher_name
->from course,teacher where course.key_teacher=teacher.key_teacher;
mapx實現查詢
1 屬性查詢。find search方法 注意的是find方法只支援tab表檔案,不支援空間資料 表。find 與foxpro中locate定位命令想類似。search 支援sql語句。寫法 僅指sql語句的where 部分,且from語句中只能有乙個表 僅對單錶進行操作 select from l...
mybatis通過中間表關聯查詢
這裡是高階查詢 現在有三個表 user,role,user role 根據三個表建立對映實體類 class user public class userrole 這裡把user,role 放到userrole裡是最簡單的方式,當乙個user對應多個role的時候,這樣寫取出多個role也是最方便的,...
資料結構 PHP實現查詢表
基本演算法 假設有乙個陣列,需要找出某個值在該陣列中的位置。二分查詢 function bin sch array low high k elseif k array mid else return 1 順序查詢 function seq sch array n k if i n else 測試 a...