English 中文(简体)
比较两个 Mysql 数据库中的数据
原标题:Comparing data in two mysql database

我有两个 Mysql 数据库。 我必须比较第一个数据库中第一个表格的列数据与第二个数据库的列数据。 在两个数据库中, 表格名称和列名称都是一样的。 我必须找到共同的数据。 列是一个 varchar 字段。 但问题在于“ Newyork times” 和“ times newyork” 和“ newyork” 。 我无法生成 sql 查询。 这是我尝试过的程序 。

drop procedure if exists test;
delimiter #
create procedure test()
begin

declare v_max int unsigned default 243;
declare v_counter int unsigned default 1;
declare pName varchar(255);

start transaction;
while v_counter < v_max do
select t.property_name from t.property where t.property_id=v_counter into pName;
SELECT distinct b.property.property_name,b.property.property_id from b.property where    b.property.property_name like  % +pName+ % 
set v_counter=v_counter+1;
end while;
commit;
end #

delimiter ; 

能否进行类似的比较?

问题回答

无法让 MySQL 做如此模糊的比较。 它无法知道以下哪一种应该被视为“ 相同 ” 。

  • newyork times
  • new york times
  • t
  • york

如果你有数量有限的"错误" 你可以在调查中把它们正常化

WHERE t.property_name = REPLACE(v.property_name,  new york times ,  new york )

当然,这些“非常”和“非常”很快变得无法管理。

您可以添加一个新的列, 即使是暂时的 。 这样您就可以在一套预密文件里对数据进行某种清理 。

UPDATE t
SET cleanpropertyname =  new york times  
WHERE property_name IN ( new york times ,  new york ,  nyt )




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签