dbTalk Databases Forums  

Join on a substring

comp.databases.mysql comp.databases.mysql


Discuss Join on a substring in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Electricdummy
 
Posts: n/a

Default Join on a substring - 09-24-2010 , 01:56 PM






I have problems making a query, maybe someone can help.

What do I have:
A standard select * from 'table_a' where .... query
In this table there is a string which contains a unique number/string
from
table_b, lets call this column "special_string".
This string starts always at position x and this string is followed by
a
":".

I want to join both tables on this substring and "special_string"

Any Ideas how I can acchieve this?

Alexander

Reply With Quote
  #2  
Old   
Luuk
 
Posts: n/a

Default Re: Join on a substring - 09-24-2010 , 02:48 PM






On 24-09-10 20:56, Electricdummy wrote:
Quote:
I have problems making a query, maybe someone can help.

What do I have:
A standard select * from 'table_a' where .... query
In this table there is a string which contains a unique number/string
from
table_b, lets call this column "special_string".
This string starts always at position x and this string is followed by
a
":".

I want to join both tables on this substring and "special_string"

Any Ideas how I can acchieve this?

Alexander
if you have a table which contains all nummbers from 1 upwards to 1000

and you do
SELECT * from numbers where locate('2', number)-locate('1', number)=1;

than you will get all numbers like:
12
120
121
122
123
123
124
125
126
127
128
129
312
412

it really does not matter much that this is not a JOIN......

--
Luuk

Reply With Quote
  #3  
Old   
Peter H. Coffin
 
Posts: n/a

Default Re: Join on a substring - 09-24-2010 , 02:55 PM



On Fri, 24 Sep 2010 11:56:52 -0700 (PDT), Electricdummy wrote:
Quote:
I have problems making a query, maybe someone can help.

What do I have:
A standard select * from 'table_a' where .... query
In this table there is a string which contains a unique number/string
from
table_b, lets call this column "special_string".
This string starts always at position x and this string is followed by
a
":".

I want to join both tables on this substring and "special_string"

Any Ideas how I can acchieve this?
If you plan to use this more than once, add a column to hold the
substring, populate it with something like

UPDATE mytable SET mysubcol = SUBSTR(myothercol, 37, 14);

then throw an index onto that column. If you want to use this for a long
time, add a trigger to populate that column every time you insert a row
or update your other column.

--
77. If I have a fit of temporary insanity and decide to give the hero
the chance to reject a job as my trusted lieutentant, I will retain
enough sanity to wait until my current trusted lieutenant is out of
earshot before making the offer. --Anspach's Evil Overlord List

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.