开发者

How do I find out the index in a MySQL table

开发者 https://www.devze.com 2022-12-17 19:53 出处:网络
I\'m programming in PHP5 & MySQL5 and I\'d like to know how to figure out the index of an entry. To be clear, here\'s an example:

I'm programming in PHP5 & MySQL5 and I'd like to know how to figure out the index of an entry. To be clear, here's an example: I have 500 users in a table, I want to select the user johndoe and the index of that user, so if johndoe is the 100th user in my table, I want to be able to select the information for him in a similar way to this:

SELECT *, INDEX_OF(id) FROM users WHERE username='johndoe';

So I'd get the details about the user back (name, username, id, index etc...) Plea开发者_运维知识库se note this is different than the ID of the user.

How would I go about doing this?

Thank you!


You can use the _rowid special column, but it is just the same as an "unsigned int auto_increment primary key", i.e. what you would normally call "id".

SQL has no requirements on order of the rows searched, only on returned rows. That means you can't count on that entry being at the 100th position for every search. So in that sense, any attempt to find the physical position of the row, could possibly return a different result each time.

0

精彩评论

暂无评论...
验证码 换一张
取 消