Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2011
    Posts
    16

    Unanswered: Delete left outer join

    Hello, I am at the moment trying to delete a LEFT OUTER JOIN i created for a CMS website on PHP my LEFT OUTER JOIN looks like this:

    '$sqlQuery = "SELECT filename FROM phpland LEFT OUTER JOIN
    images ON phpland.image_id = images.id WHERE phpland.id = '$pageid' ";

    In this case phpland and images are the name of my tables and the $pageid is the id I'm passing to it, yet it seems to work no problem but when I attempt to delete it I'm trying:

    'DELETE filename from phpland AS filename LEFT OUTER JOIN images
    ON phpland.image_id = images.id WHERE phpland.id = '$pid' "

    Same situation Im passing the ID and I'm even echoing the ID on PHP to make sure is the ID I wish to delete but it tells me the ID is ambiguos, I'm not sure what I am doing wrong the primary Key on the table images.id is a foreign key on phpland as image_id
    I do hope this was not confusing for anyone, any type of help is highly apprecciated.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    My first guess is that you want something like:
    PHP Code:
    $sqlQuery "DELETE FROM phpland WHERE phpland.id = '$pid' " 
    Your DELETE query doesn't reference anything in the images, so there is no need to JOIN it. This is only a guess at what you want, so think about it carefully then try it in a development and/or test environment and check what it does there.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Oct 2011
    Posts
    16
    I guess I almost got it I'm implementing this : DELETE image_id FROM phpland WHERE phpland.id = '$pid'" but I do get : nknown table 'image_id' in MULTI DELETE
    I guess that's when i cam out with the idea of the JOIN however I apprecciate your inpout a lot

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    You can't delete one column, you have to delete the whole row. Remove the image_id from the statement that you posted, and you will then match my suggestion which will delete that entire row.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

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