473,498 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to compare two columns in DB2 -Please HELP!

Hello,

I need to compare two columns in two tables and to find the rows with
partially matched result. For example, 'Jim' is deemed as matching
'Jimmy' and 'Jeff ' as matching 'Jeffery'. In Microsoft jet
(or in sql server similarly) this can be done by using:

"SELECT tableA.column1, tableB.column1 FROM tableA INNER JOIN tableB
ON tableA.column1 LIKE tableB.column1 & %".

But in db2, 'LIKE' operator can not be used on column. Do you have
any idea how to do this in DB2?

There must be a way to do it in DB2 if it can be done elsewhere easily.
What do you DB2 experts think?

Any help is appreciated,

James

Jan 9 '06 #1
3 14985
James You wrote:
Hello,

I need to compare two columns in two tables and to find the rows with
partially matched result. For example, 'Jim' is deemed as matching
'Jimmy' and 'Jeff ' as matching 'Jeffery'. In Microsoft jet
(or in sql server similarly) this can be done by using:

"SELECT tableA.column1, tableB.column1 FROM tableA INNER JOIN tableB
ON tableA.column1 LIKE tableB.column1 & %".

But in db2, 'LIKE' operator can not be used on column. Do you have
any idea how to do this in DB2?

There must be a way to do it in DB2 if it can be done elsewhere easily.
What do you DB2 experts think?

SELECT tableA.column1, tableB.column1 FROM tableA INNER JOIN tableB
ON SUBSTR(tableA.column1, 1, LENGTH(tableB.column1)) = tableB.column1
AND tableA.column1 >= tableB.column1

I added the >= predicate for performance only. It may give you a start
key (or not).

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Jan 9 '06 #2
SELECT tableA.column1, tableB.column1 FROM tableA INNER JOIN tableB
ON LOCATE(tableB.column1, tableA.column1) = 1;

Jan 9 '06 #3
Thank you to both of you! Serge and Tonkuma
James

Jan 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5110
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows...
10
27451
by: xixi | last post by:
we are using db2 udb v8.1 on windows, i would like to know whether we have tool or way to compare two tables on same database for data difference. thanks. (same ddl, different data, try to compare...
0
1478
by: Peter Wang | last post by:
I have a function and am using cursor. All the columns I select in the cursor clause are BYTEA datatype. I need to compare the after-fetch-value for two BYTEA columns which is temp2 and temp3...
8
2534
by: mjf | last post by:
I need to come up with a tool to compare the table definition and/or its data before and after some modification to the DDL or some tests (that change the data). Does DB2 come with such a tool, or...
17
4489
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
11
35371
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
3
9241
by: mcolson | last post by:
I am trying to compare the last two values in the same column of a table. First of all, I have a column titled Row_Index that uses an index which starts at 1 and increments by 1. What I am trying...
5
4995
by: Yas | last post by:
Hello, I have the following table with 4 columns.... firstname, lastname1, lastname2, EMAIL Table has user names and email, I would like to generate a 5th column called DisplayName. The email...
2
5080
by: pratyushavasireddy | last post by:
i need to compare two columns .and return the result which is not matched. for example if i have pratyusha in one column and pratyusha vasireddy in other column.when i compare two columns i should...
1
2858
by: Jollywg | last post by:
I have 1 file that I need to compare two columns and count how many account names (column1 ie jollywg) do not have a /home directory with that name (column 6 ie /home/jollywg). The file name is...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.