Inserting the result of mysql_query() into the same database?

You can easily combine the two : INSERT INTO server_main(server_nmea, server_rmc_time, signal, server_latitude, north, server_longitude, east, speed, track_angle, server_rmc_date) SELECT nmea, rmc_time, signal, ROUND((FLOOR(latitude/ 100) + (latitude - 100 * FLOOR(latitude/ 100)) / 60), 5), north, ROUND((FLOOR(longitude / 100) + (longitude - 100 * FLOOR(longitude / 100)) / 60), 5), east, speed, track_angle, str_to_date( rmc_date, '%d%m%y' ) FROM server_imports.

That is what I think I did at first but the records returned were few – ibiangalex Nov 9 '10 at 14:19.

You can actually do it all in one step: INSERT INTO server_main(server_nmea, server_rmc_time, signal, server_latitude, north, server_longitude, east, speed, track_angle, server_rmc_date) SELECT nmea, rmc_time, signal, ROUND((FLOOR(latitude/ 100) + (latitude - 100 * FLOOR(latitude/ 100)) / 60), 5), north, ROUND((FLOOR(longitude / 100) + (longitude - 100 * FLOOR(longitude / 100)) / 60), 5), east, speed, track_angle, str_to_date( rmc_date, '%d%m%y' ) FROM server_imports.

If the data types are not matching your target fields consistently or if you are selecting identical rows such that a target table UNIQUE KEY constraint will be violated, you won't be able to insert as many rows as you select. – dnagirl Nov 9 '10 at 14:37 Thanks dnagirl, 45 out of 100 were returned. It was just a sample data at first.

Your point is right, I had to remove the indexes before doing the insertion. Because of the nature of the data, there would certainly be duplicates which I do not know how to handle while doing the insertion with the php script. I do know that I could remove the duplicates after.

Many thanks for your useful opinion. – ibiangalex Nov 9 '10 at 16:21 @ibiangalex: you don't need to remove the indices. You have several choices.

Have a look at SELECT DISTINCT, INSERT IGNORE, REPLACE, and INSERT ... ON DUPLICATE UPDATE – dnagirl Nov 9 '10 at 17:52.

You can do it in one query. Just INSERT the rows you get with your existing SELECT. INSERT INTO ... SELECT ... Check out the docs for more details.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions