943,672 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 907
  • Perl RSS
Jun 24th, 2009
0

Compare 2 tables

Expand Post »
Hi everybody,
I want to compare 2 tables contents. My tables are:
Table1
------------------
ID || Value
------------------
1 || forum_list1
2 || Message_list1
3 || Search1
4 || Search5
5 || Search11
6 || Log_out
7 || LOG

Table2
--------------------------------------------
ID || Value1 || Value2
---------------------------------------------
1 || rd_forum_list1_no ||
2 || wr_Message_list1_yes ||
3 || rd_Search1_no ||
4 || rd_Search5_no ||
5 || rd_Search11_no ||
6 || rd_Log_out_no ||
7 || rd_LOG_no ||
8 || wr_forum_list1_no ||
9 || rd_Message_list1_yes ||
10 || 123_Search1_456 ||
11 || 123_Search11_456 ||

I want to compare both the tables content and if the contents are similar then place the ID of table no. one in Table2.Value2 but discard all the rows with "wr_". Also note that in case of Search1 and Search11, I want the comaprison very exact as

Table2
--------------------------------------------
ID || Value1 || Value2
---------------------------------------------
1 || rd_forum_list1_no || 1
2 || wr_Message_list1_yes ||
3 || rd_Search1_no || 3
4 || rd_Search5_no || 4
5 || rd_Search11_no || 5
6 || rd_Log_out_no || 6
7 || rd_LOG_no || 7
8 || wr_forum_list1_no ||
9 || rd_Message_list1_yes || 2
10 || 123_Search1_456 || 3
11 || 123_Search11_456 || 5

I tried implementing this by following code:
$query = "SELECT Table1.value, Table2.value1 FROM Table1,Table2 WHERE Table2.value1 LIKE CONCAT('%',Table1.value,'%')";
$result =mysql_query($query) or die(mysql_error());
while(@row = mysql_ftech_array($result))
{
$updatetable2= UPDATE Table2.value2 SET Table2.value2 =(@Table1.value);
}

But its not working.. please help..
thanks in advance
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
me8042 is offline Offline
3 posts
since Jun 2009
Jun 27th, 2009
0

Re: Compare 2 tables

If u are running code in Unix

Then run two sql quires

one for table one > redirect to file1
and for table two > redirect to file2

then do
sdiff file1 file2 > file3
grep for lines other than "|" pipe symbol
and use cut command
Reputation Points: 10
Solved Threads: 6
Light Poster
msvinaykumar is offline Offline
48 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: Duplicate lines in a text file
Next Thread in Perl Forum Timeline: Simple Benchmark script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC