Take the 2-minute tour ×

I want to use javascript to fetch data with yql from flickr, e.g.

select id from flickr.photos.search(10) where text = 'music' and license=4

however, I would like to fetch 10 random rows, rather then the latest, since the latest tend to be 10 photos all from the same person.

ist that possible in yql itself (I suspect not), or any workarounds that could bring the same effect? (it does not have to be complete random, the main thing I want to avoid is to get 10 photos from the same poster)

share|improve this question
add comment

1 Answer

To get only results from unique owners, you can use the unique() function (docs).

My suggestion would be to query for a larger result set (more likely to have 10 unique people) then call unique() followed by truncate() to limit to 10 results, as below.

select id from flickr.photos.search(100) where text = 'music' and 
license=4 | unique(field="owner") | truncate(count=10)
share|improve this answer
that was my first try as well, unfortunately it does not really help; people upload loads of photos, so I really have to take a huge subset to make sure the probability that i get several owners are really high, which would make the request take very long time –  JohnSmith Jul 11 '11 at 10:00
Without bringing back a large dataset (or multiple datasets) from Flickr, you won't be able to get "random" or "unique" results. With regards to the original question asked, if the underlying API offers "random" results then so can YQL. Otherwise, good luck. Related discussion, flickr.com/groups/api/discuss/72157618101421766 –  salathe Jul 11 '11 at 10:37
add comment

Your Answer


