SQL Delete Problem (mysql)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TomyB

    #1

    SQL Delete Problem (mysql)

    Here's on for you, any help would be greatly appreaciated as it is
    sending me mad...

    I have three tables tbl_photo, tbl_photo_galle ry and tbl_gallery.
    they are linked through primary and and secondary keys as follows:

    tbl_photo.photo _id = tbl_photo_galle ry.photo_id
    tbl_gallery.gal lery_id = tbl_photo_galle ry.gallery_id

    yeat when i try this delete it fails:

    delete from tbl_photo where tbl_photo.photo _id =
    tbl_gallery_pho to.photo_id and tbl_gallery_pho to.gallery_id = (number)

    I tried putting this directly into mysql and got the following error:

    Unknown table 'tbl_gallery_ph oto' in where clause

    the table definately exists as 'select * from tbl_gallery_pho to' works
    fine.

    If anyone can help I will buy them a pint one day... please?
  • Aggro

    #2
    Re: SQL Delete Problem (mysql)

    TomyB wrote:
    [color=blue]
    > delete from tbl_photo where tbl_photo.photo _id =
    > tbl_gallery_pho to.photo_id and tbl_gallery_pho to.gallery_id = (number)[/color]

    You need a syntax similar to this example:

    DELETE test FROM test AS t1, test2 WHERE ...

    But you should also know that multi-table-delete doesn't work with older
    versions of MySQL. You didn't mention what version you are using so
    can't say if it works for you, but you can read it for yourself from the
    manual. Direct link to correct page below:

    http://dev.mysql.com/doc/mysql/en/DELETE.html

    Comment

    • Daniu

      #3
      Re: SQL Delete Problem (mysql)

      TomyB ??:[color=blue]
      > Here's on for you, any help would be greatly appreaciated as it is
      > sending me mad...
      >
      > I have three tables tbl_photo, tbl_photo_galle ry and tbl_gallery.
      > they are linked through primary and and secondary keys as follows:
      >
      > tbl_photo.photo _id = tbl_photo_galle ry.photo_id
      > tbl_gallery.gal lery_id = tbl_photo_galle ry.gallery_id
      >
      > yeat when i try this delete it fails:
      >
      > delete from tbl_photo where tbl_photo.photo _id =
      > tbl_gallery_pho to.photo_id and tbl_gallery_pho to.gallery_id = (number)
      >
      > I tried putting this directly into mysql and got the following error:
      >
      > Unknown table 'tbl_gallery_ph oto' in where clause
      >[/color]
      The table name you defined above is 'tbl_photo_gall ery '.[color=blue]
      > the table definately exists as 'select * from tbl_gallery_pho to' works
      > fine.
      >
      > If anyone can help I will buy them a pint one day... please?[/color]

      Comment

      Working...