UPDATE c_discounts_test AS t1
INNER JOIN
(
SELECT *
FROM c_discounts_test
WHERE assigned = 0
ORDER BY RAND() LIMIT 1
) AS t2
ON t1.id = t2.id
SET t1.assigned = 1, t1.discount_code = t2.hash, user_id = [user_id];
select discount_code from c_discounts_test WHERE user_id = [user_id];
Please Log in to join the conversation.
UPDATE c_discounts_test AS t1
INNER JOIN
(
SELECT *
FROM c_discounts_test
WHERE assigned = 0
ORDER BY RAND() LIMIT 1
) AS t2
ON t1.id = t2.id
SET t1.assigned = 1, t1.discount_code = t2.hash, t1.user_id = [user_id];
Please Log in to join the conversation.
Please Log in to join the conversation.
UPDATE `#__discounts_test` SET `user_id` = '[user_id]' WHERE `user_id` IS NULL LIMIT 1
SELECT `coupon` FROM `#__discounts_test` WHERE `user_id` = '[user_id]' LIMIT 1
It's a keyword so I wouldn't use it. Typically you want to avoid using keywords. Reserved keys would flat out error. The below is a list of reserved keys and keywords.I also have a feeling that calling one of my columns 'hash' is not a good idea!!
Please Log in to join the conversation.
UPDATE c_discounts_test AS t1
INNER JOIN
(
SELECT *
FROM c_discounts_test
WHERE user_id IS NULL LIMIT 1
) AS t2
ON t1.id = t2.id
SET t1.user_id = [user_id];
Please Log in to join the conversation.
Ah, ok. Neat usecase!Oh I forgot to mention that the reason behind generating discount_codes in advance is because when people register in my website and get the discount_codes, they will use it in another website developed by other people. So, I needed to give those other developers a table with previously generated discount codes in order to make sure that users are members in my website so they can give them discounts in their own website..
Please Log in to join the conversation.