SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    UPDATE MySQL Query - Datafeed

    I have three tables, let's say: `books`, `descriptions`, `datafeed`.

    `books`
    +--+-----+
    | id | pid |
    +--+-----+
    | 1 | p25 |
    | 2 | p26 |
    +--+-----+

    `descriptions`
    +---+------+
    | id | text |
    +---+------+
    | 1 | text-1 |
    | 2 | text-2 |
    +---+------+

    `datafeed`
    +----+-------+
    | pid | text |
    +----+-------+
    | p25 | text-1 |
    | p26 | text-2 |
    +----+-------+

    I need to pass (text) value from `datafeed` table to `descriptions` table (text) column through `books` table WHERE books.id=descriptions.id

    PHP Code:
    UPDATE `descriptions
    SET `text` = (SELECT `textfrom `datafeedWHERE `datafeed`.`pid` = `books`.`pid` AND `books`.`id` = `descriptions`.`id`) 
    WHERE EXISTS (SELECT 1 from `datafeedWHERE `datafeed`.`pid` = `books`.`pid` AND `books`.`id` = `descriptions`.`id`); 
    I'm trying to write SQL query, but struggle with it. Please check what's wrong with the above query.

    I appreciate any of your help.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Code:
    UPDATE descriptions 
    INNER
      JOIN books
        on books.id = descriptions.id
    INNER
      JOIN datafeed
        ON datafeed.pid = books.pid
       SET descriptions.text = datafeed.text
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Appeciate you so much


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
  •