如何比较mysql和php中的两个表? [英] how to compare two tables in mysql and php?

查看:30
本文介绍了如何比较mysql和php中的两个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我又遇到了麻烦!

表 1

  • n: 1
  • n:2
  • n:3

Table2

  • n: 1
  • n:3

查询 1

  • 结果数量:3

查询 2

  • 结果数量:2

我需要比较这些表,如果 Table1 == Table2 回显找到".所以我做了 2 个不同的查询,我是这样做的:

I need to compare this tables and if Table1 == Table2 echo "found". So i made 2 diferent querys and Im doing it like this:

while($row1 = mysql_fetch_array($Query1))
{
while($row2 = mysql_fetch_array($Query2))
{
if($row1['n'] == $row2['n'] )
{
echo 'found';
}
}
}

有点傻?:\ 因为它似乎只显示第一个结果并停止.

Kinda dumb? :\ cause it seems show just the 1st result and stop.

谢谢

示例:我得到了这张表:客户和表:VIP 客户.如果有任何具有相同 ID 的客户端,我需要在表 VIP 客户端上进行搜索,并得到一个回声:找到它"

Exmpl: I got this table: clients, and table: VIP clients. I need to search on table VIP clients if there is any client with same id, and result an echo: "found it"

推荐答案

不确定这是否是您想要的,但是您可以通过一个查询来查看 vipclients 中是否有任何匹配的记录.

Not sure if this is what you want, but you could do it in one query to see if there is any matching records in vipclients.

select a.*,b.* ,CASE WHEN b.clientid IS NOT NULL 
       THEN 'FOUND'
       ELSE 'NOT FOUND'
END AS vipexists 
from clients a left outer join vipclients b on a.clientid=b.clientid

这篇关于如何比较mysql和php中的两个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆