If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > Using where like

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-01-09, 13:34
petrybr petrybr is offline
Registered User
 
Join Date: Mar 2008
Posts: 7
Lightbulb Using where like

Hello,

I have two tables..

The first has a column whith data like this:

A99999

the second has a column whith data like this:

XXX0000/Zxy_A99999_1234

I want to select data from the second table using the first table, something like this:

select * from second where second.column like '%first.column%'

Any sugestion how can i do that?

I'm using informix..
Reply With Quote
  #2 (permalink)  
Old 09-01-09, 14:20
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
in ANSI SQL, you would use this --
Code:
WHERE second.column LIKE '%' || first.column || '%'
by the way, did you know we have an Informix forum?

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-01-09, 14:21
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
I don't know what functions Informix has available but I would look for one that can locate a character string in another string.

In DB2 it would be something like:

WHERE LOCATE(COL1, COL2) > 0

This would search for the value of COL1 (A99999) in COL2(XXX0000/Zxy_A99999_1234) and return the starting position of that value. A 0 indicates it is not found so "> 0" indicates it was in the string. If you have that function it may be called something else.
Reply With Quote
  #4 (permalink)  
Old 09-02-09, 02:55
JarlH JarlH is offline
Registered User
 
Join Date: Dec 2008
Location: At work...
Posts: 68
ANSI/ISO SQL has POSITION:

<string position expression> ::=
POSITION <left paren> <string value expression>
IN <string value expression> <right paren>


e.g ...WHERE POSITION(COL1 IN COL2) > 0
Reply With Quote
  #5 (permalink)  
Old 09-02-09, 16:36
petrybr petrybr is offline
Registered User
 
Join Date: Mar 2008
Posts: 7
Quote:
Originally Posted by r937
in ANSI SQL, you would use this --
Code:
WHERE second.column LIKE '%' || first.column || '%'
by the way, did you know we have an Informix forum?


tks man, worked!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On