Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6558221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:10:22+00:00 2026-05-25T13:10:22+00:00

I am having a bit of a problem with some mysql. I will try

  • 0

I am having a bit of a problem with some mysql. I will try to give a much background as I can. This is the situation, I had created an availability for my parent’s plant nursery and stored the plant information in mysql, I did a terrible job the first time and now I am redoing it with the new knowledge I have gained in the mean time.

Background of the problem, I had 2 tables in the old database one being called Gallery with the following fields:

(id, Plant_id_1, Plant_id_2, Plant_id_3, Plant_id_4, Plant_id_5, Image1, Image1_Copyright, Image2, Image2_Copyright, Scientific, Common, Category, Height, Spread, Exposure, Zone, Descp).

The Plant_id_1... fields would be the id of the second table which is called Availability with the following fields:

(id, name, size, description, available, upcomming, price)

So as you can see I knew nothing about datases(still might not) but on to the new structure for the table, again 2 tables the first being called plants with the following fields:

(id, scientific_name, common_name, category, height, spread, exposure, usda, description, image1_url, image1_copyright, image2_url, image2_copyright)

The second being called current with the following fields:

(id, plant_id, size, available, upcoming, price, description)

The plant_id will be the id of the corresponding plant in the plant table.

Now on to the problem. I need to get the data from the old table and put it into the new table. I have all the plants from gallery in the new plant table no issue there. But now to get the Availability into the Current table.

This is an example from the export of the Availability (I took the top 3):

INSERT INTO `Availability` (`id`, `name`, `size`, `description`,`available`, `upcomming`, `price`) VALUES(91, 'Acer P.''Shishigashira''', ' #5', '30-36"', 27, 0, 36.00); 

INSERT INTO `Availability` (`id`, `name`, `size`, `description`, `available`,`upcomming`, `price`) VALUES(697, 'Arbutus U. ''Compacta''', ' #5','', 0, 0, 16.20); 

INSERT INTO `Availability` (`id`, `name`, `size`, `description`, `available`, `upcomming`, `price`) VALUES(90, 'Acer P.''Shigitatsusawa''', '#15', '', 0, 0, 65.00);

I need to get the plant_id from the plant table and put that into a insert statement, which I believe I have with the following:

INSERT INTO `current` (`plant_id`, `size`,`description`, `available`, `upcoming`, `price`) VALUES(
(SELECT  `id` 
FROM  `plants` 
WHERE  `scientific_name` 
REGEXP  'Acer P.+ ''Shishigashira'''),  ' #5', '30-36"', 27, 0, 36.00);

But now I have a new problem what if there is no plant in the plant table to match, So i need a ifnull in there. to create the plant with the scientific name and the rest null. well I am new to SQL so this is what I have and its not working:

INSERT INTO `current` (`plant_id`, `size`,`description`, `available`, `upcoming`, `price`) VALUES(
(IFNULL( SELECT IFNULL( (SELECT `id` 
FROM  `plants` 
WHERE  `scientific_name` 
REGEXP  'Chamaecyparis O.+ Nana'),( 
INSERT INTO  `plants` (`scientific_name`)
VALUES (Chamaecyparis O. 'Nana'))))),  ' #1', '', 0, 0, 9.25);

As you can see Its very complicated if you think you are up to the challenge of helping me i would beyond greatly appreciated. If no one can help me I will have to manually reenter all the data into the current table.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:10:23+00:00Added an answer on May 25, 2026 at 1:10 pm

    You should work towards a select that returns the data you need to insert into your new table. Once
    you have that you can simply wrap that into a INSERT INTO – SELECT contruction. That way you don’t have to export and do individual inserts. You can simply copy the whole set over in one go.

    If you make sure that when you copy plants from the gallery into the plants table the id’s stay intact I expect a select like this should return the rows you want to insert:

    SELECT 
       Gallery.id as plant_id, 
       Availability.size, 
       Availability.available, 
       Availability.upcoming, 
       Availability.price,
       Availability.description
    FROM Gallery 
    INNER JOIN Availability
    ON Gallery.Plant_id1 = Availability.id
    

    Then you can do the same thing 5 times where you change the

    ON Gallery.Plant_id1 = Availability.id
    

    to (one by one)

    ON Gallery.Plant_id2 = Availability.id
    ON Gallery.Plant_id3 = Availability.id
    ON Gallery.Plant_id4 = Availability.id
    ON Gallery.Plant_id5 = Availability.id
    

    Or you put all of them together in one huge sql statement with a UNION ALL between each select

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I'm having some difficulty with CSS and IE6 compatibility. URL : http://bit.ly/dlX7cS Problem
I'm having a bit of a problem with converting the result of a MySQL
Having a bit of problem with some syntax trying to insert HTML after an
I'm having a bit of a jQuery problem. Basically I have some functions that
I'm having a bit of an odd problem while trying to compile some code
I'm having a bit of a problem deciding how to store some data. To
I'm having a bit of a problem finding out how to cancel this task
Having a bit of a problem, Due to the source-control set-up we use, each
Having a bit of a problem creating an instance of an object. Bear in
I am having a bit of a problem. I get a RAW char* buffer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.