Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select first and last row from group_concat when grouping sortable days

Referring to my previous questions about the group concat Mysql again, group by and display rest of rows

i need to get first and last day from that query

for example

row 3 from 8,9,10 to first collumn 8, last collumn 10
row 5 from 21,22,23,24,28,29,30 to first collumn 21, last collumn 30
row 6 from 17,21,22,23,24,25 to first collumn 17 last collumn 25

SUBSTR(GROUP_CONCAT(DAY),-1) as fl

BUT it gives me last char, and there are few rows with 1 or 2 chars for example

1,2,3,22
1,3,6,3

In first example it gaves me 2, not 22 :/

like image 239
breq Avatar asked May 25 '12 12:05

breq


1 Answers

Another option (besides Michael's solution) is to use the SUBSTRING_INDEX:

SUBSTRING_INDEX(str,delim,count)

with

count = 1

you get the first day,

with

count=-1

you get the last one

like image 71
Th0rndike Avatar answered Oct 14 '22 12:10

Th0rndike