关联表查询

来源:互联网 发布:零基础看谁的java视频 编辑:程序博客网 时间:2024/05/21 11:04
电话记录表 c_phone_record 
Id, phone_number, phone_source 
1    62332222       1
2    62331111       2
3    61122345       1




电话来源表 c_phone_source
ID 名称name
1  96105
2  12345








select name 
from c_phone_record
join c_phone_source
on c_phone_record.phone_source=c_phone_source.ID

where phone_number =62331111;


student表 s
id name code 
1   yh   001 
2   sz   002


cource表 c
id name
1  yw
2  sx


s_c表
id sid cid  sc 
1  1    1
1  1    2
1  2    1




select s.name
from s_c
join cource 
on  c.id=sc.cid
join  student
on s.id=sc.sid
where c.name = yw;






select 目标
from 目标所在表
join 目标关联表
on 目标主键=关联键
where 已知条件


0 0
原创粉丝点击