0

I had created a table; however, every time I insert a row the data does not show up in the order I inserted, any reasons why?

For example,

I inserted rep 20 with all its needed info and so forth, then rep 30, and rep 40.

But the order comes out like this

30
40
20

as opposed to

20
30
40

Thanks in advance.

SQL_Student
  • 671
  • 1
  • 5
  • 3

2 Answers2

2

does not show up in the order I inserted

Rows in a relational database do NOT have any "order". Think of them as balls in a basket.

The only (really: the only) way you can guarantee an order when selecting data is to use an order by clause.

0

If you want the results of your SELECT to be in a certain order, you must include an ORDER BY clause. Without ORDER BY, the results can be in any order; it doesn't even need to be in a consistent order.

Assuming that your REP table has a column called id, your query would look like:

SELECT * FROM REP ORDER BY id
ZoogieZork
  • 11,215
  • 5
  • 45
  • 42