-4

I have single table name test with field1, field2 and field3

Field1     Field2    Field3
a             x        10
a             x        20 
b             g        30 
b             g        40  
c             u        50
c             u        60

I want to see group Field1, Field2, (NOT Field3) and return all value Field3

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user1203397
  • 67
  • 1
  • 2
  • 8

1 Answers1

0

Your question is very unclear. If i understand your question correctly, this is what you want right? You didn't mention to SUM up the values in Field3 or MAX, MIN or etc.

SELECT Field1, Field2, Group_Concat(Field3)
FROM tableName
GROUP BY Field1

Result:

Field1     Field2    Field3
a             x        10, 20 
b             g        30, 40
c             u        50, 60

UPDATE

as i read the comment, you want this query:

SELECT group_concat(Distinct Field1),
       GROUP_CONCAT(DISTINCT Field2),
       GROUP_CONCAT(Field3)
FROM tableName;

will Result:

Field1     Field2    Field3
a,b,c      x,g,u       10, 20 , 30, 40, 50, 60
John Woo
  • 258,903
  • 69
  • 498
  • 492
  • Try this but error on sql 2008 Msg 195, Level 15, State 10, Line 2 'group_concat' is not a recognized aggregate function. Please help agian – user1203397 Feb 13 '12 at 19:31
  • @user1203397 what server are you using? `group_concat` is available on MySQL and SQLite, other than that you have to create a function same with functionality of `Group_Concat` – John Woo Feb 14 '12 at 01:03