左联:select a.xxx,b.ccc from tableA a left join tableB b on a.id=b.id
内联:select a.xxx,b.ccc from tableA a inner join tableB b on a.id=b.id
右联:select a.xxx,b.ccc from tableA a right join tableB b on a.id=b.id
你说的是一对多吧,父子关系多难听,
一对多可以用left join 链接查询
select * from account left join tbs on account.id=tbs.cd我刚好有这么一条sql
mysql:1、先给B表添加主键列
alter table tableB add constraint b_PK primary key(date,channel)
2、将B表的组合主键关联到A表的外键组合键中
alter table tableB add constraint tableB_fk foreign key(date,channel) references tableA (date,channel) on DELETE CASCADE
3 delete from tableA where date =? and channel =? 就出发相关记录··~
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)