EE 3.1.4
I need to get a detail field from a grid field, but I also need the results to be distinct. The issue I have is the grid field returning a pipe delimited field set.
So running something like this:
{exp:query sql="SELECT DISTINCT field_id_23 AS bedroom_count FROM exp_channel_data WHERE channel_id=3"}
{bedroom_count}
{/exp:query}
yields results similar to:
315,000|3|2|2|1|2374
...but be able to return the distinct values from a particular segment inside that set like just the field that, in this case, was '3'.
Is there a way to better do this? I need to stash them in a stash list to be used in a ddl selection.
* ANSWER *
I wish I could accept two answers for this. Derek provided what I asked for, but Stuart made me fix my original mistake.
I originally had this being done with stash. My mistake was that I had this:
{!-- BATHROOMS --}
{exp:channel:entries channel="house" dynamic="no" limit="999999"}
{exp:stash:set_list name="bathroom_counts" parse_tags="yes" parse_depth="2"}
{house_details}
{stash:bathrooms}{house_details:bathrooms}{/stash:bathrooms}
{/house_details}
{/exp:stash:set_list}
{/exp:channel:entries}
And fetched it like this:
{exp:stash:get_list name="bathroom_counts" unique="yes"}
<li>{bathrooms}</li>
{/exp:stash:get_list}
The problem I was having, besides being extremely tired at the time, was creating my list within the channel:entries
loop.
I needed the following:
{!-- BATHROOMS --}
{exp:stash:set_list name="bathroom_counts" parse_tags="yes" parse_depth="2"}
{exp:channel:entries channel="house" dynamic="no" limit="999999"}
{house_details}
{stash:bathrooms}{house_details:bathrooms}{/stash:bathrooms}
{/house_details}
{/exp:channel:entries}
{/exp:stash:set_list}