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 na开发者_StackOverflow中文版mes 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
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.
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.
精彩评论