Jump to content

Recommended Posts

Pardon?

 

The picture show one of my field that is ID(Auto Increment) Format(BIGINT)

 

My main question is if I want to retrieve the ID as it was from database, I want the ID to be arrange from first number 

 

because the number was 116,117 and 118 and I want it start from 1

Edited by shebbycs

I'm with Jessica on this one.  If you find the need to change the ID, then your design needs work.  There is no reason to change the ID, as then you can/will corrupt the data protocols, especially if that table is tied to other tables through the PRIMARY KEY.

I'm guessing that the question is: how do you reset the auto_increment id for a table back to 1?

 

This will only work if all the rows are removed from the table, either with DELETE or TRUNCATE table.

ALTER TABLE yourtable AUTO_INCREMENT = 1;
To accomplish this with renumbering, you can select into a temp table and then reinsert, omitting the old id column.
CREATE TABLE t_yourtable AS SELECT * FROM yourtable;
TRUNCATE TABLE yourtable;
ALTER TABLE yourtable AUTO_INCREMENT = 1;
INSERT INTO yourtable (col2, col3... etc) SELECT col2, col3... etc FROM t_yourtable;
*Note* I think that truncate table may set the auto_increment back to 1, but test it with our version just to be sure.

trq and gizmola sir let me describe in detail based on below picture

 

countercas.jpg

 

This is my field and the branch_codename is location and I had 23 location and for testing I just put 2 location only

 

Let say if the ID number from table above was arrange from 1 so there will be 1 -5 number and my search query will be where branch_codename='TK02'

 

for sure it will return ID number 2 and 4

 

My main question was if I call the location and using html table I want the number sorting back to 1 and 2  instead of 2 and 4

 

How to do that please :)

Edited by shebbycs

You need to do that in your procedural code. When you get the result set, you can use a variable and as you fetch each row you increment that counter variable. It is not something you do in SQL or in trying to manipulate your query results.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.