| Author |
Topic |
|
demetris20
Starting Member
8 Posts |
Posted - 2011-10-11 : 13:39:24
|
| helloi have a forum and i mess it up with the aql commands i have 2 tables that have 3 rowsthe 2 rows are the same and the third one its differentso i was wondering if i can copy the 3 row from the first table to the row of the other table by using the other 2 rows as a linkthanksdemetris20 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-11 : 13:46:38
|
| very vague question. can you at least show sample of how data exists in both tables with some sample data and give what output you're expecting out of them?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
demetris20
Starting Member
8 Posts |
Posted - 2011-10-11 : 13:59:17
|
| ok here is some examplethere are 2 tables one called posts and the other one called topicsboth tables have the follow rows-column called the sametopic id and forum idfrom the topics table the third rows its called topic_poster and from post table its called poster_idi want the topic_poster to be insert into the poster id as all poster_id is 0 after i mess it upso i was wondering if it can be done |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-11 : 14:17:14
|
| [code]insert posts (poster_id)select distinct topic_posterfrom topics[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
demetris20
Starting Member
8 Posts |
Posted - 2011-10-11 : 14:47:23
|
| i will try it and let you now but the actual tables are called phpbb_topics and phpbb_postsdo i replace it with that thanks |
 |
|
|
demetris20
Starting Member
8 Posts |
Posted - 2011-10-11 : 16:42:37
|
| SQL ERRORField 'post_text' doesn't have a default value [1364]this is the result i got |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-12 : 01:37:56
|
| what is value you want to populate for post_textsince you dont have default value specified you need to pass a value for it.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jassi.singh
Posting Yak Master
122 Posts |
Posted - 2011-10-12 : 05:17:13
|
| You can use merge statement feature of sql server 2008, have a google on itPlease mark answer as accepted if it helped you.Thanks,Jassi Singh |
 |
|
|
demetris20
Starting Member
8 Posts |
Posted - 2011-10-12 : 08:08:11
|
| ok i will try and explain morei have a php website and 72 sql tablesthe 2 tables i want to compine are called phpbb_topics and phpbb_poststhe phpbb_topics have the following fieldstopic_idforum_idicon_idtopic_titletopic_posterand the phpbb_post the followingpost_idtopic_idforum_idicon_idposter_idpost_subjectpost_titletopic_id,forum_id,icon_id have the same values row,type etcthe topic_poster and poster_id had the same as the other table but when i did something wrong the poster_id had nothing us a valuebut because the topic_poster keep having the records from the poster id i want to copy those value and put them in the poster_idso i am looking of an sql command to take the value the topic poster value and copy them in the place of the poster_idi can try and make it one by one but will take ages as there are more than 10000 pages with 30 rows eachbasically i am looking something like thistake from phpbb_topic where topic_id and forum_id=phpbb_posts topic_id and forum_id take the topic_poster from phpbb_topics and put it in the phpbb_post in where it is the poster_idi hope this will make more sence |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-12 : 08:35:04
|
| [code]update ppset pp.poster_id= pt.topic_posterfrom phpbb_post ppjoin phpbb_topics pton pt.topic_id = pp.topic_idpt.forum_id = pp.forum_idpt.icon_id = pp.icon_id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
demetris20
Starting Member
8 Posts |
Posted - 2011-10-12 : 08:46:42
|
| i believe the command its like thisUPDATE phpbb_posts SET phpbb_posts.poster_id = phpbb_topics.topic_posterFROM phpbb_postsJOIN phpbb_topics ON phpbb_topics.topic_id=phpbb_posts.topic_idphpbb_topics.forum_id=phpbb_posts.forum_idphpbb_topics.icon_id=phpbb_posts.icon_idif yes then i will post the result in 5 seconds |
 |
|
|
demetris20
Starting Member
8 Posts |
Posted - 2011-10-12 : 08:49:28
|
| SQL query:UPDATE phpbb_posts SET phpbb_posts.poster_id = phpbb_topics.topic_poster FROM phpbb_posts JOIN phpbb_topics ON phpbb_topics.topic_id = phpbb_posts.topic_idphpbb_topics.forum_id = phpbb_posts.forum_idphpbb_topics.icon_id = phpbb_posts.icon_idMySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM phpbb_postsJOIN phpbb_topicsON phpbb_topics.topic_id = phpbb_posts.top' at line 2 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-12 : 09:02:17
|
it should beupdate ppset pp.poster_id= pt.topic_posterfrom phpbb_post ppjoin phpbb_topics pton pt.topic_id = pp.topic_idand pt.forum_id = pp.forum_idand pt.icon_id = pp.icon_id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-12 : 09:03:38
|
| One more thing. just noticed you're using mysql. this is ms sql server forum. so solutions given here are sql server specific. You can try given suggestion. In case its not working in MYSQL, please try your luck at www.dbforums.com. We dont have much expertise in MySQL------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
demetris20
Starting Member
8 Posts |
Posted - 2011-10-12 : 09:07:07
|
| yes you are right it didnt workthanks for the advice though |
 |
|
|
|