MySQL Select Row Order

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

SELECT * FROM SectionQuestion WHERE SectionID = 5

When those rows are retrieved, am I always guaranteed that they will be retrieved in the same order (as long as no indexed column is added to the table, or more rows added with a SectionID of 5)?

After a couple of test queries, the answer appears to be yes, but I'd like a definitive answer Smiling

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

And yes, I know that I could add another column that contains the order in it, but that's not my question.

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

try deleting out a row from the middle of the ones returned to you, then add another row.

I did this earlier today, and it put the new record where the one I just deleted was.

When you need to make sure it is the same, give it rules to follow to make sure can (add PK or Order field and sort with it).

-Greg

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

I did this earlier today, and it put the new record where the one I just deleted was.

I experienced the same behavior. I'm still unsure if I'm always guaranteed that will happen but I guess I'll take my chances. Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.