I have a query that gets 5 random values out of a table according to a query. i.e.

SELECT * FROM links WHERE url contra = FALSE ORDER BY rand() LIMIT 0,5

This is fairly simplified but you get the idea. One of the fields in the table is ip, how can I do that same but ensure that all the ip values are DISTINCT. Any ideas anybody?

I have a query that gets 5 random values out of a table according to a query. i.e.

SELECT * FROM links WHERE url contra = FALSE ORDER BY rand() LIMIT 0,5

This is fairly simplified but you get the idea. One of the fields in the table is ip, how can I do that same but ensure that all the ip values are DISTINCT. Any ideas anybody?

Would this do the trick?

SELECT DISTINCT ip, * FROM links WHERE url contra = FALSE ORDER BY rand() LIMIT 0,5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.