I am storing values into a table with an SQL INSERT
query
Query:
INSERT INTO tbl_Deta ([ID NO], [OR NO], [ITEM DESCRIPTION], QUANTITY, UNIT)
VALUES (6,0,'ring gauge',44,nos)
INSERT INTO tbl_Deta ([ID NO], [OR NO], [ITEM DESCRIPTION], QUANTITY, UNIT)
VALUES (6,0,'asd',14,ads)
INSERT INTO tbl_Deta ([ID NO], [OR NO], [ITEM DESCRIPTION], QUANTITY, UNIT)
VALUES (6,0,'amd',33,asd)
Result:
[ID NO] [OR NO] [ITEM DESCRIPTION] QUANTITY UNIT
6 0 asd 14 ads
6 0 ring gauge 44 Nos
6 0 amd 33 asd
I want result in the same order in which the data are inserted and not in the alphabetical order.
There is no inherent order inside a table.
There is no pre-stablished order when you insert rows. If you do a
Without an
ORDER BY
then no particular order will be used. If you want some particular sorted results, you must use anORDER BY
clause. You could use a primary key and sort according to its values.There are several questions/answers that could help you to get a better understanding of this particular point:
I was just reading through my RSS feeds and found an awesome blog entry by Michael J. Swart. All the best answers on this subject in one entry, great!
Retrieving rows in the same order they were inserted is not a standard guaranteed SQL feature. I suggest adding another column that you can order by, for example an identity/autonumber integer field, or perhaps a date inserted.
how is your table actually looking? You can look this up like this:
If you have a column storing creation date (typically named "created_at"), you can easily order by creation date:
However, as mentioned in the comments, an auto-incremented field might be the better way to go.
If I am imagining your order entry system correctly, you probably have a list of items in that order id. I encourage you to have an
ITEM ID
column, but you have toORDER BY
when youSELECT
. As an added benefit this ITEM ID helps you, in case you need toUPDATE
.