Mysql SQL:将未加密值与加密值匹配
我有一张这样的桌子:Mysql SQL:将未加密值与加密值匹配,mysql,sql,Mysql,Sql,我有一张这样的桌子: ------------------------------------- | id | name | ------------------------------------- | 1 | butter | | 2 | cheese | | 3 | steak | -----------
-------------------------------------
| id | name |
-------------------------------------
| 1 | butter |
| 2 | cheese |
| 3 | steak |
-------------------------------------
SELECT id, ENCRYPT(`name`, 'thisismycoolsalt') FROM `table`
-------------------------------------
| id | name |
-------------------------------------
| 1 | 74684a4e6b6d564b526e76674d |
| 2 | 74686e5a7379506554564b3451 |
| 3 | 74687341565776786a55704359 |
-------------------------------------
这些值的加密版本为:
-------------------------------------
| id | name |
-------------------------------------
| 1 | butter |
| 2 | cheese |
| 3 | steak |
-------------------------------------
SELECT id, ENCRYPT(`name`, 'thisismycoolsalt') FROM `table`
-------------------------------------
| id | name |
-------------------------------------
| 1 | 74684a4e6b6d564b526e76674d |
| 2 | 74686e5a7379506554564b3451 |
| 3 | 74687341565776786a55704359 |
-------------------------------------
我的问题是,如果我有该名称的加密版本,如何选择具有未加密表单的行
我正试图这样做,但这是不正确的语法:
SELECT *
FROM `table`
WHERE ENCRYPT(`name`, 'thisismycoolsalt')='74684a4e6b6d564b526e76674d'
您所做的应该是有效的,如图所示: 带有
JOIN
子句的版本:
SELECT
plain.id, plain.name,
encrypted.id AS e_id, encrypted.name AS e_name
FROM encrypted
INNER JOIN plain ON ENCRYPT(plain.name, encrypted.salt) = encrypted.name;
带有简单WHERE
子句的版本:
SELECT *
FROM plain
WHERE ENCRYPT(name, 'thisismycoolsalt') = 'thsAVWvxjUpCY'
数据:
Plain table :
ID NAME
1 butter
2 cheese
3 steak
Encrypted table :
ID NAME SALT
1 thJNkmVKRnvgM thisismycoolsalt
2 thnZsyPeTVK4Q thisismycoolsalt
3 thsAVWvxjUpCY thisismycoolsalt
如果您需要更多帮助,也许可以发布您遇到的语法错误。这就是我喜欢的表格