0

I want to return data in unique action_id (comma separated values) from a table using singme SQL query

For example table: tbl_action

action_id
----------
101
102
103     
104
102
105

Output that I want is: 101,102,103,104,105
STEVE001
  • 181
  • 2
  • 10

1 Answers1

2

You can use Group_concat() function with Distinct:

SELECT GROUP_CONCAT(DISTINCT action_id) FROM tbl_action;

If you want the action_id values to be in ascending order in the comma separated string, you can do the following:

SELECT GROUP_CONCAT(DISTINCT action_id ORDER BY action_id) 
FROM tbl_action;
Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57