Multiple values stored in single field with relationship to table.

i have inherited a mysql database and the developers have used muliple values in a field seperated with an @ symbol.
this field contains reference numbers which relate to another table in the database.

ok so table 1 has this

propid       Charac
1             @41@869@48@874@877@878@879@881@885@870@898@901@903@
2             @41@869@48@874@877@878@879@881@885@870@898@901@903@

Table 2 has this
keyid           descr
41              desc1
42              desc2
869            desc3
48              desc4
etc


i want to run a query so i get this

propid           Descr
1                   desc1
1                   desc3
1                   desc4
2                   desc1
2                   desc3

is this possible??
Thanks all!!


Craigster2006Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoonaanCommented:
It would have been for more easier when he/she would have used comma's rather than @'s. Is it possible for you to change this easily, or is that not going to work for the rest of the application?

-r-
0
Craigster2006Author Commented:
Hi,
unfortunately its not possible to change the @ symbol - this is a db for another app.
0
m1tk4Commented:

select * from table1 join table2 on table1.charac like concat('%@',table2.keyid,'@%)

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Muhammad WasifCommented:
try this one

select table1.propid, table2.descr from table2
INNER JOIN table1 ON
table2.keyid IN (REPLACE( SUBSTRING(table1.Charac,2), '@', ','))
0
limneosCommented:
$query1="SELECT * from table1 where 1";
$result1=mysql_query($query1);
while ($row=mysql_fetch_array($result1)){
$a=explode("@",$row[Charac]);
foreach ($a as $value){
if ($a!=""){
$query2="SELECT * from table2 where keyid='$value'";
$result2=mysql_query($query2) or die(mysql_error());
$row2=mysql_fetch_array($result2);
print "$row[propid] $row2[descr]<br>";
}
}
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Craigster2006Author Commented:
Thanks Perfect man!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.