0

This is my table tb_currency_minimum_amount enter image description here

When I am inserting a record using

INSERT IGNORE INTO tb_currency_minimum_amount ( id, currency_id, payment_method, minimum_amount) VALUES (NULL, 1, 16, 0.02) 

again and again it creates a new entry

rows with id 32,33,34 are same

It i assigning it id 32 not 27 and ignoring duplicates

2:enter image description here

2
  • :fyi in mysql auto increment id work as +1 with last id ..have you been deleted records after 27 meanwhile you are working Commented Aug 17, 2017 at 9:26
  • I have not deleted rows @AnkitAgrawal Commented Aug 17, 2017 at 9:32

3 Answers 3

2

The purpose of an AUTO_INCREMENT column is to ensure unique identifiers for the rows in the table.

It is just an implementation detail that it uses consecutive integer values. It is not a requirement for these values to be consecutive. Your code must not rely on the values being consecutive.

The value of the AUTO_INCREMENT is increased by each INSERT statement when a value for that column is not provided, no matter if the updated value is used (the query creates a new row) or not (it fails because of a duplicate key constraint or it updates an existing row because of ON DUPLICATE KEY).

Sign up to request clarification or add additional context in comments.

3 Comments

so what is the possible solution @axiac
In order to find a solution you have to clearly define the problem. I cannot see any problem in the question. The rows with IDs 32, 33 and 34 are similar because you ran the query 3 times. Apart from the PK, is there any UNIQUE index on the table?
these currency_id, payment_method,minimum_amount can not be unique as per the problem statement @axiac
0

Auto increment is count every record with +1. But it does not check of other columns are unique or duplicates. In your id column which is auto increment I do not see any duplicates.

Could you elaborate your purpose what you trying to archive.

2 Comments

rows with id 32,33,34 are same @Noob
@art12345 you mean the colomn currency_id ? If you mean this it is right that it has the same id since there are no restrictions regarding duplicates in row. You can solve this to change to unique colomn.
-1

It is adding assigning it id 32 not 27 and ignoring duplicates

If i understand your question correctly, you should use the SQL SELECT DISTINCT Statement.

The SELECT DISTINCT statement is used to return only distinct (different) values.

Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.

The SELECT DISTINCT statement is used to return only distinct (different) values.

1 Comment

But i am inserting not fetching records @Lea Krause

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.