取得这张表:

id | field1 | foreign
 1    abc       12
 2    def       12
 3    abc       13
 4    def       13


我选择这样的记录:

"SELECT field1 FROM table WHERE foreign = 12"




"SELECT field1 FROM table WHERE foreign = 13"


现在考虑我的表,该选择返回完全相同的记录值。
如何判断给定2个任意SELECT,它们在SQL中重新调整相同的值?

PS。考虑到您正在投票解决这个问题,我对此进行了重新表述。谢谢
PS2。我有除field1以外的其他领域
PS3。我知道我可以通过PHP做到这一点,但是有没有一种方法可以使用纯SQL?

最佳答案

您可以使用md5sum确认2个结果集是否相等,这在比较两个大结果集时非常有用。只需在mysql控制台中使用以下命令:

传呼机md5sum-

这将设置MySQL寻呼机在每次运行查询后显示MD5Sum。

如果使用PHP运行每个查询,则可以使用以下方法创建相同的效果:

// This method will return MD5 of a result set. Compared results will return the same     MD5Sum if they have the same results, and are ordered in the same way.
function query_md5($sql) {
 $rs = mysql_query($sql);
 $num = mysql_num_fields($rs);
 $str = "";
 while ($obj = mysql_fetch_array($rs)) {
  $i = 0;
  while ($i < $num) {
   // no need for spaces or formatting
   $str .= $obj[$i++];
  }
 }
 return md5($str);
}


希望这可以帮助!

10-08 08:00
查看更多