I have a bunch of testimonials in a channel. Some have the exact same value in the title field.

My code looks like:

FROM exp_channel_titles 
WHERE channel_id=19 

    {exp:channel:entries channel="testimonials" disable="categories|member_data|pagination" 
    search:title="{the_title}" dynamic="no" limit="1"}




How can I insure I do not get more than one entry with the same title?

I can write a little SQL if needed.


  • Hey Ben, if the issue is solved, you need to select the appropriate answer to close out the question. It tells people which answer worked, as well as improves the site stats. Commented Apr 13, 2013 at 12:25

3 Answers 3


Updated query:

{exp:query sql="SELECT tmp.entry_id AS entryId
FROM (SELECT entry_id, title FROM exp_channel_titles WHERE channel_id='1' AND status='open' ORDER BY RAND()) tmp 
GROUP BY tmp.title LIMIT 5"}
    {exp:channel:entries entry_id="{entryId}" disable="categories|member_data|custom_fields|pagination|trackbacks}

You need to pass correct channel_id within WHERE clause.

You can see, I am applying the GROUP BY clause on random records so that query can group the entries based on random order otherwise each time query will return the top most record having duplicate Title.

I hope, it would be workable for you.

  • Thanks - but getting zero results when trying in the CP's database query form.
    – 4midori
    Commented Apr 9, 2013 at 19:15
  • Plz let me check also. May be, there is something wrong in query. Commented Apr 10, 2013 at 4:31
  • I updated my query. Can you try it. It would work. Commented Apr 12, 2013 at 17:35

I believe Ian's response is the closest to what you need. I'd modify the query to:

{exp:query sql='SELECT DISTINCT title FROM exp_channel_titles WHERE channel_id='3' ORDER BY RAND() LIMIT 3'}



I'm not certain why the channel:entries tag was introduced. It's not needed. Now there could be a debate about whether the items are truly random, since the DISTINCT statement is used. But they aren't forbidden from being used together.

So this should work. Make sure, the channel_id matches the id from testimonials.

  • Yes, this query will work but what about if one need to show other channel data with/without title. I believe, there other channel data also be shown. Commented Apr 13, 2013 at 1:57
  • He only asked for de-duplicating the title. If needs to select from multiple channels, he can just use MySQL' IN function like WHERE channel_id IN(1,3,5) for multiple channels, if he needs them. But based on the questions, this is an issue specific to pulling client testimony from a single channel called testimonials where title and the data field, say testimony have same data. Commented Apr 13, 2013 at 4:49
  • For simply fetching non-duplicate titles only your solution is good and easy to use. Commented Apr 13, 2013 at 10:48
  • 1
    Why are you introducing {exp:channel:entries}? The {exp:channel:entries} tag will perform it's own query, pretty much invalidating the specifics of the both the DISTINCT and RANDOM functions. If you just want 3 random and distinct titles, my query as is (well modifying channel_id to match yours) should work. Adding the {exp:channel:entries] re-queries the database, with it's own parameters. I can't see any reason why'd anyone would add {exp:channel:entries} it to a query function. It must produce a ton of inconsistencies. Is this a standard practice? Commented Apr 16, 2013 at 19:11
  • 1
    Just tried the query again, against a database where I introduced duplicate titles and expanded the search across three sections, which I know ail include more duplicates, then set return to 50 records at a time (the database has over 4000 records. Ran the query 10 times, not a single duplicate title. Try it without introducing {exp:channel:entries}. I'm not certain of your reasons for adding it, but it ignores the returns from the original query and introduces it's own. Commented Apr 16, 2013 at 20:59

If you happen to already be using Stash, you can probably achieve this with the set_list and get_list methods in combination with the unique="yes" parameter.

If you're not already using Stash, then the query module approaches would be best.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.