Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009
    Posts
    3

    Unanswered: please help with query!

    Hi

    I have 2 tables: Person and PersonCar - something like this:

    CREATE TABLE `database1`.`Person` (
    `id` INTEGER UNSIGNED NOT NULL,
    `name` VARCHAR(100)) NOT NULL,
    `added_date` DATETIME NOT NULL,
    PRIMARY KEY (`id`)
    )



    CREATE TABLE `database1`.`PersonCar` (
    `id` INTEGER UNSIGNED NOT NULL,
    `person_id` INTEGER UNSIGNED NOT NULL,
    `plate_no` VARCHAR(50) NOT NULL,
    PRIMARY KEY (`id`)
    )



    This is how I delete for those from 2008 or older (delete car aswell if person has a car):

    DELETE Person, PersonCar FROM Person LEFT OUTER JOIN PersonCar ON Person.id = PersonCar.person_id WHERE Person.added_date < '2009-01-01 00:00:00'


    My question is: how do I make backup to 2 other identical tables Person_backup and PersonCar_backup in 1 query - in the same manner as the above delete query (copying car is person has a car)?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    can't be done in one query
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2009
    Posts
    3
    i can do this programmatically with csharp (more than one query) - but is it possible to make this backup without involving programming? the goal is to just open the mysql query browser and fire a sql syntax - if this requires more than one query thats fine..

  4. #4
    Join Date
    Apr 2009
    Posts
    3
    bump - please anyone?

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    bumping is frowned upon

    and anyhow, you answered your own question -- use two queries

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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