SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Manage and copy data between two tables

    Hi, this is driving me crazy, and I coundīt find any post related on Sitepoint forum (and on the web) that may answer my problem, so I am hoping that someone here will

    I have two tables:

    Code:
    TableA
    referid 	allthreads
    empy 	1663
    empy 	1662
    empy  	8754
    empy 	8555
    empy 	8701
    
     ---- 
    TableB
    article_id 	thread_id
    10664 	1663
    10630 	1662
    1655  	1661
    10641 	1655
    10622 	1654

    I need to copy all the "article_id" entries from TableB into "referid" from TableA that are related between thread_id (TableB) and allthreads (TableA).

    So far, my best query, which gives me an error, and probably really wrong, is:

    Code:
    INSERT INTO TableA(
    referid
    )
    SELECT article_id
    FROM TableB
    WHERE (SELECT allthreads FROM TableA) = ANY (SELECT thread_id FROM TableB)
    I would really, really appreciate your help on this. THANKS in advance just for reading my confusing issue

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You want to update those rows, not add new ones, right?

    Code:
    UPDATE TableA, TableB 
    SET TableA.referid = TableB.article_id
    WHERE TableB.thread_id = TableA.allthreads

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much Dan Grossman. I am not a MySQL expert, not even a novice xD , and this little query was killing me. Again, thank you so much for look at it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •