Results 1 to 3 of 3
  1. #1

    PHP/SQL Embedded Query

    I need to do a double query, where one is embedded in the other. I am not sure how to format this code near the bottom.

    PHP Code:
    $sql mysql_query("UPDATE table SET valueA = 'hello' 
    WHERE ValueB = '2' 
    AND ValueC = '3' 
    AND ValueD IN (SELECT ValueD FROM NewTable)"
    I don't believe an UPDATE can use a JOIN....may be wrong on that. So, I am trying to use an embedded query like I have above with the "IN" keyword. How do I format that exactly? Thanks.
    TextAdMarket -
    Supply & Demand Advertising

  2. #2
    Join Date
    May 2007
    Orange Country, CA
    From the MySQL manual:

    Single-table syntax:

    SET col_name1=expr1 [, col_name2=expr2 ...]
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]

    Multiple-table syntax:

    UPDATE [LOW_PRIORITY] [IGNORE] table_references
    SET col_name1=expr1 [, col_name2=expr2 ...]
    [WHERE where_condition]
    If you're trying to update multiple tables use the multiple-table syntax. You can use any join statement campatible with SELECT inside a multiple-table UPDATE. Here's an example:

    UPDATE table1 INNER JOIN table2 ON SET table1.value='value1', table2.value='value2' WHERE table1.value2>'value3'
    I hope that helps.
    Blesta - Professional Billing Software
    We are about creating good experiences
    Trial - Demo | 866.478.7567 | Twitter @blesta

  3. #3
    it sure does. Thank you!
    TextAdMarket -
    Supply & Demand Advertising

Posting Permissions

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