mysql - best way to provide unique voucher
One way to do it is to update and select in the same statement; and add a condition to the statement so that (if selected, don't select again)

Here is my way:

SET @voucher_id=0;
UPDATE voucher_table SET status=1, v_id = (SELECT @voucher_id := v_id) WHERE status=0 LIMIT 1;
SELECT * FROM voucher_table WHERE v_id=@voucher_id;


It is kind of creating an artificial lock. Notice that any other transaction (or user) won't be able to pick up the same voucher ID due to the Atomicity and Isolation in ACID properties of the database systems.