Click here to Skip to main content
15,885,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a table region with fields : country and city
like below :

table region

kode | city
--------------

indonesia | jakarta

malaysia | kuala lumpur

i want to insert record city with comma where country indonesia
the result :

country | city
--------------
indonesia | jakarta, bandung, jogja

malaysia | kuala lumpur


how to create a sql query for that ??
Posted
Comments
Santosh K. Tripathi 4-Feb-15 23:51pm    
Hi,

I need to know

1. length of City Field.
2. How are you adding city? Means while inserting new country you are adding multiple city at same time or you want to update city flied by adding one more cityin existing cites.

It can but should not be done. Never put multiple values in a single cell. It is against 1NF principle. In relational database design, every cell must not take more than one value, like separated with commas. They should be separated into multiple rows.
Read more: 11 important database designing rules which I follow[^]
 
Share this answer
 
Peter mentioned a very valid point. But, in case you have to do it, here is the way:

UPDATE Region
SET City = 'jakarta, bandung, jogja'
WHERE country = 'Indonesia'
 
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