SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Sql help needed:

  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    UK
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sql help needed:

    Hi all,

    I'm trying to delete entries in two tables by using:

    PHP Code:
    $query "DELETE FROM gallery, pictures WHERE gallery.gid=$gid && pictures.gid=$gid";
    $result mysql_db_query($DBName$query$connection) or die ("Error in query: $query. " mysql_error()); 
    It coming back with this error though:

    PHP Code:
    You have an error in your SQL syntax near ' pictures WHERE gallery.gid=15 && pictures.gid=15' at line 1 
    What am I doing wrong

    Any help would be appreciated.

    Matt

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,768
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe that you can not delete from more that one table at a time.

    EDIT:My mistake above. This is from the manual:
    The first multi-table delete format is supported starting from MySQL 4.0.0. The second multi-table delete format is supported starting from MySQL 4.0.2.
    The idea is that only matching rows from the tables listed before the FROM or before the USING clause are deleted. The effect is that you can delete rows from many tables at the same time and also have additional tables that are used for searching.
    The .* after the table names is there just to be compatible with Access:
    DELETE t1,t2 FROM t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id
    or
    DELETE FROM t1,t2 USING t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id
    In the above case we delete matching rows just from tables t1 and t2.

    MySQL Reference Manual (C) 2002 MySQL AB
    John

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    UK
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would i have to delete using two seperate statements then?

    I tried that but it only deleted the gallery, not the pictures which shared the same gallery id.

    I'm using Mysql 4.0

    Matt

  4. #4
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,768
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hopefully you saw my edit on post #2
    John

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
  •