SELECT
s.key1,s.key2,c.key2 as gene,c.key3 as location
FROM
test2 s
JOIN
test3 c
ON
s.key1=c.key1
*test2 和 test3 是两个表,test2 是多(学生表), test3是小(班级表)
*一对多是最基础的表间关系,意思是一张表A中的一条记录可以对应另一张表B中的多条记录,另一张表B中的一条记录只能对应一张表A中的一条记录
*将上述查询的结果放入新表test中
insert into test (key1,key2,key3)
select....
*其他常用的语句
insert into test (keyd,id) VALUES(8,3)
select * from table1 where id in(select id from table2)
create table test3(keyd int(18),id int(3))
drop table test
CREATE TABLE newTb AS SELECT * FROM oldTb
数据库操作,一对多表
于 2022-08-08 12:01:33 首次发布