[ar] [ast] [bg] [br] [ca] [co] [cpf] [cs] [da] [de] [en] [eo] [es] [eu] [fa] [fon] [fr] [gl] [id] [it] [ja] [lb] [nl] [oc] [pl] [pt] [ro] [ru] [sk] [sv] [tr] [uk] [vi] [zh] Espace de traduction


{fusion sql_field}

August 2010 — updated on : October 2010

All the versions of this article:

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:

  1. <BOUCLE_tous(ARTICLES)>
  2. #TITRE
  3. </BOUCLE_tous>

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.

  1. <BOUCLE_extrait(ARTICLES){fusion id_rubrique}>
  2. #TITRE
  3. </BOUCLE_extrait>

Applied examples

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

  1. <BOUCLE_comment(FORUMS){plat}{par date}{inverse}{0,10}{fusion ip}>
  2.        <INCLURE{fond=inc/intro_commentaire}{id_forum}>
  3. </BOUCLE_comment>

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:

  1. <BOUCLE_years_with_articles(ARTICLES){par date}{inverse}{fusion YEAR(date)}>
  2.     [(#DATE|annee)]
  3. </BOUCLE_years_with_articles>

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

Show the template of this page Site powered by SPIP | Translation area | Private area