views:

257

answers:

2

i have a table named locations of which i want to select and get values in such a way that it should select only distinct values from a column but select all other values .

table name: locations column names 1: country values : America, India, India, India column names 2: state/Province : Newyork, Punjab, Karnataka, kerala

when i select i should get India only once and all the three states listed under India . is ther any way..??? sombody please help

+1  A: 

You want it displayed in that order, not selected?

In this case you have to add a condition inside of your loop to check a country and print ot out only if it was changed.

Col. Shrapnel
ya it is a good idea.. works fine ..thanks..
+2  A: 

You could do this:

SELECT country, GROUP_CONCAT(state SEPARATOR ', ')
FROM locations
GROUP BY country

But this sort of thing is often best done in the presentation layer.

Mark Byers
yes it works , can i get in an array format???
What do you mean by 'array format'? MySQL doesn't have arrays. I think you shouldn't be formatting of data for presentation in the database. You should do it in your presentation layer.
Mark Byers
ok.. ya that is what i have to do .. thanks