与md5(concat())mysql进行左连接比较
首先,我为我的英语感到抱歉 我想比较生成md5的两条记录: 我在表2中插入我从表1中获得的信息与md5(concat())mysql进行左连接比较,mysql,left-join,Mysql,Left Join,首先,我为我的英语感到抱歉 我想比较生成md5的两条记录: 我在表2中插入我从表1中获得的信息 INSERT INTO table2 (id_table_2, hash_string) SELECT t.id, MD5 (CONCAT (t.firstname, t.lastname)) AS hash_string FROM table1 t WHERE t.id = $some_value 之后,我想知道表1中的哪些记录在表2中不存在,但我无法得到我想要的结果。我这样做: SELECT
INSERT INTO table2 (id_table_2, hash_string)
SELECT t.id, MD5 (CONCAT (t.firstname, t.lastname)) AS hash_string
FROM table1 t WHERE t.id = $some_value
之后,我想知道表1中的哪些记录在表2中不存在,但我无法得到我想要的结果。我这样做:
SELECT t.id, MD5(CONCAT(t.firstname, t.lastname)) , ti.hash_string
FROM table1 t
LEFT JOIN table2 ti ON (t.id = ti.id_table_2
AND MD5(CONCAT(t.firstname, t.lastname)) != ti.hash_string)
WHERE t.state = 2
但它不起作用
我想要的是表1中的记录,这些记录不在表2中,但在那里,如果md5散列不同,也显示它。但我没能得到它。我感谢你能给我的一切帮助。谢谢。也许你想要这个,请看最后添加的行,我也更改了
=代码>至=
:
SELECT t.id, MD5(CONCAT(t.firstname, t.lastname)) , ti.hash_string
FROM table1 t
LEFT JOIN table2 ti ON (t.id = ti.id_table_2
AND MD5(CONCAT(t.firstname, t.lastname)) = ti.hash_string)
WHERE t.state = 2
AND ti.id_table_2 IS NULL
这个技巧的基本形式是:
SELECT *
FROM a
LEFT JOIN b ON a.id = b.id
WHERE b.id IS NULL
我相信这会对您有所帮助(将hash_字符串移出join并附加为where子句):
很棒的biziclop,对我来说很有用。谢谢你,伙计。这正是我需要的。谢谢,我也试过了,但没有成功。他给我看了所有的唱片。感谢MD5(CONCAT(t.firstname,t.lastname))!=ti.hash_string
您应该获得HashString不匹配的oly记录。在答案中还添加了一个空条件
。请检查。太好了,它对我也有用。非常感谢你,永德拉@Yogendra@AnbalMauricioPachecoGonzlez当前位置我看你已经接受了答案。至少投这个票,让它对你有用。另外,请注意hash_string
比较中的差异。不确定,在你的真实场景中这有多重要。@YongendraSingh,我甚至不能投票。它告诉我我有15个名声。对不起。
SELECT t.id, MD5(CONCAT(t.firstname, t.lastname)) , ti.hash_string
FROM table1 t
LEFT JOIN table2 ti ON (t.id = ti.id_table_2)
WHERE t.state = 2
AND MD5(CONCAT(t.firstname, t.lastname)) != ti.hash_string
AND ti.id_table_2 is NULL;