Limit using group_contact in Mysql 5

Asked

Viewed 23 times

1

Good morning guys, I’m having a question:

I have the following SQL example:

group_concat( DISTINCT `mvu5877_anuncios_photos`.`image` ORDER BY `mvu5877_anuncios_photos`.`order` ASC SEPARATOR ',' ) AS `images`

In SEPARATOR I need to define a quantity instead of bringing all items. In Mariadb I can do this just past the Limit at the end. Example:

group_concat( DISTINCT `mvu5877_anuncios_photos`.`image` ORDER BY `mvu5877_anuncios_photos`.`order` ASC SEPARATOR ',' LIMIT 4 ) AS `images

Bad in Mysql 5.7.32 syntax error. Any suggestions?

1 answer

1


I was able to solve using the Mysql function SUBSTRING_INDEX

The final Consultation was as follows:

SUBSTRING_INDEX(
  GROUP_CONCAT(DISTINCT `mvu5877_anuncios_photos`.`image` ORDER BY `mvu5877_anuncios_photos`.`order`),
  ',',
  4
) AS `images`

Browser other questions tagged

You are not signed in. Login or sign up in order to post.