sqlmysqljoin

SQL syntax Inner Join


I keep getting a syntax error using phpmysql:

UPDATE 
  allbooks 
SET 
  allbooks.bookCoverImage = books.bookCoverImage, 
  allbooks.bookDescr = books.bookDescr, 
  allbooks.bookEbook = books.bookEbook, 
  allbooks.bookMobi = books.bookMobi, 
  allbooks.bookEpub = books.bookEbook, 
  allbooks.bookEbookPrice = books.bookEbookPrice 
FROM 
  allbooks 
  inner join books using (bookAuthor, bookTitle);

Can anyone point out my error?


Solution

  • The Join

    UPDATE 
      allbooks
      INNER JOIN books USING (bookAuthor, bookTitle)
    SET 
      allbooks.bookCoverImage = books.bookCoverImage, 
      allbooks.bookDescr = books.bookDescr, 
      allbooks.bookEbook = books.bookEbook, 
      allbooks.bookMobi = books.bookMobi, 
      allbooks.bookEpub = books.bookEbook,  -- Note: Is this correct? You're using bookEbook twice
      allbooks.bookEbookPrice = books.bookEbookPrice;
    

    The JOIN comes immediately after the table you're updating