MySQL query help

Hi All,

I have two table

Table 1:  movies
Fields:  id, data1

Table 2:  movie_likes
Fields:  id, data2

I want to prepend data1 to data2 where the ID's match.  The ID in both table only appear once in each table.

Many thanks
D
LVL 2
detox1978Asked:
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.

PortletPaulfreelancerCommented:
select
*
from table1
inner join table2 on table1.id = table2.id

not much else to go on.
0
detox1978Author Commented:
Sorry I must not have been clear enough.

I want to insert the content of data1 into data2, as "data1 + data2"
0
PortletPaulfreelancerCommented:
the term you need is "concatenate"; which will help you remember the concat() function

select
              concat(data1,data2) as prepended
from table1
inner join table2 on table1.id = table2.id

see: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

note there is also concat_ws()
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

ThommyCommented:
Use Cross Table Update...
Cross Table Update with MySQL
0
ThommyCommented:
It should go somehow like that...

UPDATE movie_likes ml, movies m
SET ml.data2 = m.data1+ml.data2
 WHERE ml.id = m.id

Open in new window

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
detox1978Author Commented:
Got it using a combination of your two posts.

UPDATE movie_likes ml, movies m
SET ml.data2 = CONCAT(m.data1,ml.data2)
WHERE ml.id = m.id
0
PortletPaulfreelancerCommented:
Thanks, sorry missed to point about updating (too much haste), cheers, Paul
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
MySQL Server

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.