[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 557
  • Last Modified:

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
0
detox1978
Asked:
detox1978
  • 3
  • 2
  • 2
2 Solutions
 
PortletPaulCommented:
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
 
PortletPaulCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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
 
PortletPaulCommented:
Thanks, sorry missed to point about updating (too much haste), cheers, Paul
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now