求助!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!简单问题,我是菜鸟

xushengming227 2007-12-19 04:43:37
2个表
比如
表1,主键a,b c,d
表2,主键c,d,e,f

查询表1有的,在表2没有的(也就是a,b)
...全文
53 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
懒得去死 2007-12-27
  • 打赏
  • 举报
回复

create table tt1 (
a int not null,
b int not null,
c int not null,
d int not null,
primary key (a,b,c,d)
);
create table tt2(
c int not null,
d int not null,
e int not null,
f int not null,
primary key (c,d,e,f)
);



create temporary table tmp1 select * from information_schema.statistics where table_schema = 'test' and table_name = 'tt1';
create temporary table tmp2 select * from information_schema.statistics where table_schema = 'test' and table_name = 'tt2';

select tmp1.column_name as diff from tmp1 left join tmp2 using(column_name) where tmp2.column_name is null;


结果:


query result(2 records)
diff
a
b
XFliangwh 2007-12-27
  • 打赏
  • 举报
回复
2楼大大答的好像与楼主的意思不同哦。

楼主的意思是否说 表1有五个属性(列):主键 ,a,b,c,d 表2的属性(列)为c,d,e,f,你想要的是表一与表二不同的列 a,b

如果是的话,数据库好像做不到这样的识别,因为数据库只认为表1和表2的c,d是不同的两个东西,只是同名而已,你要的那个应该是实现不了的。

chaoqun456 2007-12-26
  • 打赏
  • 举报
回复
就是这样
懒得去死 2007-12-19
  • 打赏
  • 举报
回复
select * from table1 where d not in (select d from table2);

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧