Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2013
    Posts
    2

    Unanswered: Help with MySQL query. Insert new record into table based on records in another tabl

    Hi,

    I need some help with a MySQL (5.6.14) query.

    I have a table "blades". This table contains blade server records, including the following columns:
    -enclosure_name
    -bay_number
    -description
    -server_name
    ...

    Each enclosure holds 16 blades servers.

    I have another table "available_bays". This table contains the following columns:
    -enclosure_name
    -bay_number
    -status
    -reserved
    -reserved_by
    -reserved_date

    I need to write a query that will scan through the blades table and for each enclosure that has less than 16 blades, write a row to the available_bays table with enclosure_name and bay_number. The used enclosure bays may not be consecutive. In other words, the servers in enclosure1 may be in bays 1-8, 10, 13-16. So in this example, I would need to end up with the following records in the available_bays table:

    enclosure_name bay_number
    enclosure01 9
    enclosure01 11
    enclosure01 12

    Also, it would need to insert the record in the available_bays table only if the same enclosure_name and bay_number do not already exit.

    Any help on creating this query would be greatly appreciated.

    Thanks,
    David

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    I need to write a query that will scan through the blades table and for each enclosure that has less than 16 blades, write a row to the available_bays table with enclosure_name and bay_number.

    ...
    ...

    Also, it would need to insert the record in the available_bays table only if the same enclosure_name and bay_number do not already exit.

    ...
    So, is it unnecessary to insert into blades table?
    Or, had the blades table 16 rows(bay_number) for each enclosure?

Posting Permissions

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