Reputation: 17
I have written a code which transfers data between two tables in my database, but when I do transfer it across, the order is all over the place. if there a way to order the data as it is transferred?
This is the query I am using. Both tables are identical in every way.
$query = mysql_query("INSERT INTO hf_hauls (SELECT * FROM hf_hauls_input ORDER BY trip_no ASC)");
$row = mysql_fetch_array($query);
Any help would be appreciated.
Upvotes: 0
Views: 557
Reputation: 71384
The insert order of data in a table is meaningless. If you want ordered data from a database query, you need to specify the order you want in the query.
You might as well save yourself some query overhead and simply do this:
INSERT INTO hf_hauls
SELECT * FROM hf_hauls_input
There is absolutely no need to order the values in the SELECT portion of your INSERT.
Now when querying against hf_hauls
if you want an order then, specify it:
SELECT * FROM ht_hauls ORDER BY trip_no ASC
Upvotes: 1