I have a table on pgsql with names (having more than 1 mio. rows), but I have also many duplicates. I select 3 fields: id
, name
, metadata
.
I want to select them randomly with ORDER BY RANDOM()
and LIMIT 1000
, so I do this is many steps to save some memory in my PHP script.
But how can I do that so it only gives me a list having no duplicates in names.
For example [1,"Michael Fox","2003-03-03,34,M,4545"]
will be returned but not [2,"Michael Fox","1989-02-23,M,5633"]
. The name field is the most important and must be unique in the list everytime I do the select and it must be random.
I tried with GROUP BY name
, bu then it expects me to have id and metadata in the GROUP BY
as well or in a aggragate function, but I dont want to have them somehow filtered.
Anyone knows how to fetch many columns but do only a distinct on one column?