MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 18th, 2013, 01:15 PM
lexierowsell lexierowsell is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 lexierowsell User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 10 sec
Reputation Power: 0
Creating a new table with info from two different tables?

I know I am in over my head, but I am learning. Thanks for your patience in advance.

I have a table with this structure:

maxmag_kunena_messages


AND one with this structure:

maxmag_kunena_messages_text


That I want to combine to a table with THIS structure (id is a common column):

posts

Reply With Quote
  #2  
Old January 18th, 2013, 01:32 PM
lexierowsell lexierowsell is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 lexierowsell User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 10 sec
Reputation Power: 0
I managed to get all of the info from maxmag_kunena_messages into posts using:

Code:
INSERT INTO posts (`id`, `parent`, `thread`, `catid`, `name`, `userid`, `email`, `subject`, `time`, `ip`, `topic_emoticon`, `locked`, `hold`, `ordering`, `hits`, `moved`, `modified_by`, `modified_time`, `modified_reason`) 
SELECT `id`, `parent`, `thread`, `catid`, `name`, `userid`, `email`, `subject`, `time`, `ip`, `topic_emoticon`, `locked`, `hold`, `ordering`, `hits`, `moved`, `modified_by`, `modified_time`, `modified_reason`     
	FROM `maxmag_kunena_messages`     
        


However I can't seem to figure out how to add
message in maxmag_kunena_messages_text

to

message in posts

matching them based on id...

tried:

Code:
INSERT INTO posts (`message`) 
SELECT `message`     
	FROM `maxmag_kunena_messages_text`
        WHERE `maxmag_kunena_messages_text`.`id` = `maxmag_kunena_messages`.`id`
        


and

Code:
INSERT INTO posts (`message`) 
SELECT `message`     
	FROM `maxmag_kunena_messages_text`
        WHERE `maxmag_kunena_messages_text`.`id` = `posts`.`id`
        


but got error:

#1054 - Unknown column 'maxmag_kunena_messages.id' in 'where clause'

I am assuming I am missing something obvious, any one care to point out what exactly that is?

Reply With Quote
  #3  
Old January 19th, 2013, 09:24 AM
f_razzoli f_razzoli is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Italy
Posts: 36 f_razzoli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 37 m 48 sec
Reputation Power: 1
What you need is a simple JOIN. Something like:

Code:
CREATE TABLE `posts`
SELECT `mk`.`id` AS `id`, `mk`.`parent` AS `parent`, `mk`.`thread` AS `thread`, ... , `mkm`.`message` AS `message`
	FROM `maxmag_kunena` `mk` INNER JOIN `maxmag_kunena_messages` `mkm`
	ON `mk`.`id` = `mkm`.`id`;


(add the missing fields and check that the syntax is right, i didn't test it)

But maybe those table are separated for a reason (different storage engines?). Why don't you use a view, instead of merging the tables?

Reply With Quote
  #4  
Old January 26th, 2013, 08:47 AM
lexierowsell lexierowsell is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 6 lexierowsell User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 10 sec
Reputation Power: 0
f_razzoli: Thanks for your response, I will run it and let you know if it works out. I am merging the tables because I am blundering my way through an attempt at a forum import from one platform to another. Thanks again.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Creating a new table with info from two different tables?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap