0

Ok, I have 3 tables;

'bu_blogs' contains blogs which have a unique blog_id.

'bu_sites' contains sites which have a unique site_id.

'bu_blogs_done' contains id, blog_id and site_id. A new row is added to this table every time a site_id is submitted to a blog_id.

What I want to do is SELECT 2 random rows from 'bu_blogs' where a field in 'bu_blogs_done' for the particular blog_id and site_id does not exist, i.e it haven't been submitted to that blog_id yet.

Thanks

  • Stian

1 Answer 1

1

If your table isn't too big (e.g. approx 100 rows), you can use something like this simple example for the random part:

SELECT * FROM bu_blogs ORDER BY RAND() LIMIT 2

Then it's just a case of adding a WHERE clause to filter out the ones that exist in bu_blogs_done.

2
  • Yeah I know. But it's the WHERE clause I am interested in, as this uses input from 3 tables. So what would that be?
    – Stian
    Feb 14, 2011 at 21:42
  • Any, why does it have to be around 100 rows?
    – Stian
    Feb 14, 2011 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.