By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE `products` (
`id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(60) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `products` VALUES (1, 'Truck');
INSERT INTO `products` VALUES (2, 'Truck');
INSERT INTO `products` VALUES (3, 'Truck');
INSERT INTO `products` VALUES (4, 'Car');
INSERT INTO `products` VALUES (5, 'Car');
INSERT INTO `products` VALUES (6, 'Car');
INSERT INTO `products` VALUES (7, 'Bike');
INSERT INTO `products` VALUES (8, 'Plane');
INSERT INTO `products` VALUES (9, 'Train');
INSERT INTO `products` VALUES (10, 'Canoe');
SELECT name, CONCAT('B', MIN(id)) AS sku
FROM products
GROUP BY name
ORDER BY RAND() LIMIT 4;
name | sku |
---|---|
Car | B4 |
Bike | B7 |
Plane | B8 |
Truck | B1 |