几个极简的SQL连接 没毛病

本文通过具体的SQL语句示例,介绍了如何使用左连接(LEFT JOIN)和内连接(INNER JOIN)来从两个表中获取数据。展示了不同连接类型如何影响结果集,并提供了一个包含错误的示例用于学习对比。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

create table temp111(

id int,
idname varchar(12)

);

create table temp222(

id int,
idname varchar(12)

);

insert into temp222 values(1,'2000');

select t1.*,t2.idname
from temp111 t1
left join
temp222 t2
on t1.id = t2.id;

/**
 ID IDNAME IDNAME
 -- ------ ------
  1 1110   222
  1 1110   2000
  **/
select t1.*,t2.idname
from temp111 t1
inner join
temp222 t2
on t1.id = t2.id; 

/**
 ID IDNAME IDNAME
 -- ------ ------
  1 1110   222
  1 1110   2000

  ***/
  --NP
  select * from 
  table1
  left join 
  table2 on ,
  table3,
  table4
  where table3=  and table4 = 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值