Hi,

A simple group by function should work for this:

Select Fruit,GrownInStates From tbl1 Group By Fruit;

and if you want grownstates in comma separated format then you can use Group_Concat function

Select Fruit, Group_Concat(GrownInStates, SEPARATOR ',') From tbl1 Group By Fruit;

Hope this will work fine.
 --
Regards,
Manasi Save

Quoting "Ravishankar BV." <ravishankar...@mindtree.com>:
Hi,

I'm very new to SQL and databases. I need a query for the following: (I'm sure
google would have found the answer, but I could not really frame the sentence
for the task I'm looking for.  Also, please let me know how do I search in
google for such tasks - so that I can try it myself in future).
Assume I have a table like:

Sl No

Fruit

Grown in states

1

Apple

KA

2

Orange

AP

3

Banana

TN

4

Jackfruit

MH

5

Mango

MP

6

Jackfruit

MP

7

Banana

AP

8

Mango

KA

9

Banana

TN

10

Apple

MH

11

Jackfruit

AP

12

Orange

MH

13

Mango

KA

14

Apple

TN

15

Banana

MP

16

Banana

MH

17

Mango

KA

18

Orange

MP

19

Jackfruit

AP

20

Apple

TN


From the above table, I want a SQL query which will list me the unique fruits
and the states in which they are grown, like:

Apple: KA, MH, TN
Banana: TN, AP, MP, MH
Jackfruit: MH,MP,AP
Mango: MP, KA
Orange: AP,MH,MP

Thanks in advance for the help,
Ravi.
________________________________
http://www.mindtree.com/email/disclaimer.html


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=arch...@jab.org

Reply via email to