priyanka gautam
priyanka gautam

Reputation: 377

Increment record in Database

I want to increment Total by one if we insert the same Name and Age. Otherwise it should be inserted as a new row with count 1.

id     Name       Age   Total
 1    Priyanka     23     1

Upvotes: 0

Views: 67

Answers (1)

Imran
Imran

Reputation: 2941

First check if record is there

SELECT * FROM yourTableName WHERE Name = 'your name' AND Age = your age;

check if you found record from above query then

UPDATE yourTableName SET Total = youraboverecord.total+1 WHERE ID = youraboverecord.id;

Else Simply insert your record.

Upvotes: 2

Related Questions