Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
id name buyitems  cost
1  anil x;y;z     10;20;30
2  suni a;b;c     40;50;60

i wanna output like this
id name   cost1  item1    cost2   item2   cost3 item3
1  anil    10      x       20       y       30     z

plz tell me sql query thankssss
Posted
Updated 18-Feb-15 22:08pm
v2

1 solution

No, I won't.
The reason I won't is simple: it's a very, very bad design for a database table, and it will give you huge problems in the future if you carry on that way.
While it is possible to do what you want, it's clumsy, and it makes other operations later a lot, lot more complicated.

Instead, change your DB design: add one or two other tables:
PurchasedItems Table:
id
custID  (foreign key to id from Table1)
itemId  (foreign key to id from Items table)
cost    value of transaction as a numeric field

Items Table:
id
itemName       (your x, or y, or a, or b)
description    (free text description of the item)

Now when you want to fetch individual items it's pretty simple - and you can do math on the values a lot more simply as well.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900