Is there anything similar to MySQL's GROUP BY?

I have records classified by categories, I would like to take all categories without repeating. Something like:

SELECT categories FROM table GROUP BY categories

Hey @vidallgoncalves, welcome to the forum!

I'm not entirely sure of what the Select and Group by methods do but, I suppose what you want to do is group your results by a given parameter.

Right now, for Laravel you can order your results by:

Can you tell me a little bit more about your use case and your Custom types?
Are Records a Custom type and categories tags for the documents?

This issue has been closed due to inactivity. Flag to reopen.

Re-opened @vidallgoncalves.

Can you tell me how you've created your categories? Using tags? or with a custom type design to be a custom tag?

Thanks.

528/5000

Hi @Phil, thanks for the return

On my website I am separating the contents in alphabetical order, there is a menu for titles that start with A, B, C, D ...

And I would like to set up this menu dynamically, only with the title letters that exist in Prismic.

My first problem was not being able to filter the titles that start with the letter, example "title LIKE } a%}"

To get around this, I created a "Letter" field, but if I filter by that field, all records with that letter will come and I would like only one of each letter to come, so the "GROUP BY title"

Hey again,

Unfortunately there's no way to group results unless you query by a field.

What I think you can do is order your results alphabetically. Here's the information in javascript:

You can see here how I did this for my pages in the Slicemachine docs website, order alphabetically by meta_title in the api browser:
https://slice-machine.prismic.io/api/v2/documents/search?ref=X6oh3xIAACcAMBqP&q=[[at(document.type%2C+"page")]]&orderings=[my.page.meta_title]#format=json

I followed the rest API docs to do that.

Let me know if this helps.

Thanks.

Hi!
Unfortunately that doesn't help, thanks anyway. I resolved otherwise.

Hi again Vidal,

Would you mind sharing your solution that you found. This would help users in your position in the future.

Thanks.

No problems.

I don't know if it was clear what I wanted to do, but I resolved it as follows.

I created a new custom type to register the letters of the alphabet and where I register my records I include a relationship field that pulls what is registered in this new custom type of letters. So I only register a new letter when a registration that needs to appear. On the website I upload only the letters that are already registered. I'll leave the link here to see if it illustrates better the operation, it would be more or less like a dictionary.

https://novabiblia.com.br/palavras-na-biblia

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.