Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to select from table where value from another table is greather than some value?

How could I select * from table movies where seeds > 10 in table torrents? Table movies has unique id, while table torrents has id that matches the movie id. There are few torrents for each movie and having just one that has seeds greather than 10 should be selected.

The only sql I have is this where it deletes all movies which don’t have any torrents.

DELETE FROM movies WHERE NOT EXISTS ( SELECT id FROM torrents WHERE id=movies.id)

I’m not good at mysql at that level to make it, even with this example, which I also got from around here.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Help would be very much appreciated.

>Solution :

something like the following:

select *
from movies m
where exists (
  select * from torrents t
  where t.id = m.id and t.seeds > 10
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading