{fusion sql_field}

The fusion criteria is used to group together results in a SPIP loop according to the unique values of one particular field.

If a loop without the {fusion sql_field} criteria retrieves several records with the same value for sql_field, then a loop that does have the {fusion sql_field} criteria will only return one of those records.

To do so, the SQL query that is generated for this criteria includes a GROUP BY clause to deliver the desired results.

An educational example
The following loop will display the titles of all of the site’s articles:


The loop below includes a fusion criteria that applies to the section (rubrique), but which also to all of the articles, and so it will group them together for identical values of id_rubrique, and then only list a single article for each different section in its results.

<BOUCLE_extrait(ARTICLES){fusion id_rubrique}>

Applied examples

Display the 10 most recent forum messages, sorted in most recent date order, and being issued from a distinct IP address:

<BOUCLE_comment(FORUMS){plat}{par date}{inverse}{0,10}{fusion ip}>

It is likewise possible to use SQL expressions as parameter criteria. The following loop will display the list of years for which there is at least one article:

<BOUCLE_years_with_articles(ARTICLES){par date}{inverse}{fusion YEAR(date)}>

A recent community contribution shows how to use this criteria to list articles per year, then by month. See


A sort criteria {par xxx} combined with the {fusion sql_field} criteria will not necessarily return the results that you might expect.

-  <BOUCLE_a1(ARTICLES){tout}{par id_article}>
retrieves the articles sorted by id_article (from 1 to 10000 for example).

-  <BOUCLE_a2(ARTICLES){par id_article}{fusion id_rubrique}>
retrieves the articles, sorted by id_article after grouping them by id_rubrique, but these groupings are made in bulk, and therefore, a priori, not in any particular sort order!

Also refer to:

-  the doublons criteria
-  the |unique filter

Author Mark Published : Updated : 06/07/23

Translations : català, English, français, Nederlands