开发者社区> 问答> 正文

想对比A,B两个表查找完全相同的每一行数据

有A,B两个表,想用PHP将这两个表进行对比,查找两个表中每行数据是否相同,并将两个表中每行相同的数据在B表中 "Same"中写入数据"1",下面是两个表结构(两个表没有关联):
A表:
"User","Password","TLE","Address","Joined","Email"
B表:
"User","Password","TLE","Address","Joined","Email","Same"
现在想对比A,B两个表查找完全相同的每一行数据("User","Password","TLE","Address","Joined","Email"),如果都相同则在B表中的"Same"中写入1,否则"Same"写入"0"或让其为空,这个PHP怎样写,MYSQL语句怎样写,怎样去实现这功能?

展开
收起
落地花开啦 2016-02-11 13:52:34 2168 0
1 条回答
写回答
取消 提交回答
  • 喜欢技术,喜欢努力的人

    你可以再改进一下
    `update base
    set base.Same = 1
    from B base, A filter
    where filter.User = base.User
    and filter.Password = base.Password
    and filter.TLE = base.TLE
    and filter.Address = base.Address
    and filter.Joined = base.Joined
    and filter.Email = base.Email`

    2019-07-17 18:40:39
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
RowKey与索引设计:技巧与案例分析 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载