I am not able to make one clean SELECT
I have postgresql table with fields
id , providerid, deal_name
I want to make random select with unique providerid
SELECT * FROM deals ORDER BY random() LIMIT 10
How I can set this to return 10 results with unique providerid’s ?
Can your question be rephrased as:
“For each of ten randomly selected providers, find one randomly selected deal offered by that provider” ?
If so, that pretty much tells you what to do. You need two layers, one pass to randomly select ten providers, then one pass to select one random deal per provider.
Given dummy data:
Here’s one that works:
… pretty much just by implementing the phrasing above as SQL. Don’t know if it’s fast; you get the idea.
If the above rephrasing isn’t correct, please clarify your question with sample data and an example, or some more detail in your description.