如何从 table select 而另一个 table 的值大于某个值?
How to select from table where value from another table is greather than some value?
我怎么能 select * 从 table movies
where seeds
> 10 in table torrents
? Table movies
具有独特的 id
,而 table 种子具有与电影 ID 匹配的 id
。每部电影的种子很少,只有种子大于 10 的种子应该 selected。
我唯一的 sql 是它删除所有没有种子的电影。
DELETE FROM movies WHERE NOT EXISTS ( SELECT id FROM torrents WHERE id=movies.id)
我不擅长 mysql 在那个水平上做到这一点,即使有这个例子,我也是从这里得到的。
非常感谢您的帮助。
类似于以下内容:
select *
from movies m
where exists (
select * from torrents t
where t.id = m.id and t.seeds > 10
);
id 来自种子 > 10 的种子
select * from movies where movie_id in (select id from torrents where seeds > 10);
也可以写成
select a.id from movies a join torrents b on a.movie_id = b.id
where b.seeds > 10;
你需要加入第二个table
SELECT * FROM movies as m INNER JOIN torrents as t ON m.id = t.movie
WHERE t.seeds > 10
我怎么能 select * 从 table movies
where seeds
> 10 in table torrents
? Table movies
具有独特的 id
,而 table 种子具有与电影 ID 匹配的 id
。每部电影的种子很少,只有种子大于 10 的种子应该 selected。
我唯一的 sql 是它删除所有没有种子的电影。
DELETE FROM movies WHERE NOT EXISTS ( SELECT id FROM torrents WHERE id=movies.id)
我不擅长 mysql 在那个水平上做到这一点,即使有这个例子,我也是从这里得到的。
非常感谢您的帮助。
类似于以下内容:
select *
from movies m
where exists (
select * from torrents t
where t.id = m.id and t.seeds > 10
);
id 来自种子 > 10 的种子
select * from movies where movie_id in (select id from torrents where seeds > 10);
也可以写成
select a.id from movies a join torrents b on a.movie_id = b.id
where b.seeds > 10;
你需要加入第二个table
SELECT * FROM movies as m INNER JOIN torrents as t ON m.id = t.movie
WHERE t.seeds > 10