Re: INSERT statement
| From: | Michael T. Babcock | Date: | Fri, 20 Oct 2000 03:48:39 +0000 |
| Subject: | Re: INSERT statement | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3817@lists.php.net to get a copy of this message | ||
Scott Mebberson wrote:
> Is there any way to control where the a new row is added to a table.
Its hard for newcomers to databases to understand, but you _don't_ insert rows
of data into specific places in a table. You put all the information you need
for getting the data out later into a column (or more than one).
That is to say, if you need to get data out in a specific (arbitrary) order,
add a numbered field to each row. When you insert data, you may have to
re-number all the rows that come after the one you're inserting to. You need
to think in terms of why you want data in a certain order.
If you're concerned about data being in the order it was inserted, use a
timestamp field. If you want data in alphabetical order, use "order by
LastName" or the like when selecting your data.
For example:
SELECT FirstName, LastName, Age, City WHERE Age < 5 ORDER BY
LastName,FirstName GROUP BY City.
It doesn't matter in what order the data is in the table ... and it never
should.