以下面的表格为例:
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"现在考虑我的表,这个select返回完全相同的记录值。
我怎么知道给定2个任意的SELECT,它们在SQL中返回了相同的值?
PS。考虑到你正在投票结束这个问题,我重新制定了这个问题。谢谢
PS2。我有除field1之外的其他字段
PS3。我知道我可以通过PHP做到这一点,但是有没有一种纯SQL的方法呢?
发布于 2011-04-18 22:49:17
您可以使用md5sum来确认两个结果集是否相等,这在比较两个较大的结果集时非常有用。只需在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);
}希望这能有所帮助!
https://stackoverflow.com/questions/5701578
复制相似问题