Wednesday, 15 April 2015

Concat column value and variable with specific length in MySQL -



Concat column value and variable with specific length in MySQL -

i have table products , table categories. here sample data products

id | product_name | category_id 1 | leath machine | 1 2 | drilling machine | 1 3 | boring machine | 1

and here category table

id | name | symbol 1 | smt equipment | smt

i want select display me results this

id | product_name | category_id | code 1 | leath machine | 1 | smt00001 2 | drilling machine | 1 | smt00002 3 | boring machine | 1 | smt00003

how cai that.

select `products`.`id`, `product_name`, `category_id`, concat(symbol, lpad(products.id,5,'0')) code products inner bring together categories on products.category_id = categories.id;

here sqlfiddle results.

sql fiddle demo

mysql

No comments:

Post a Comment