A 表 B 表
name products name level
mary pro1 mary 5
mary pro2 linda 3
linda pro3 lee 1
lee pro4
lee pro5现在要取其中前20 条数产品,用户的等级从高到低列出
我写的SQL语句
select products from A where name in ( select level from B order by level desc) limit 20;
感觉这种嵌套查询不对,如果用连接查询,该如何写呢?
name products name level
mary pro1 mary 5
mary pro2 linda 3
linda pro3 lee 1
lee pro4
lee pro5现在要取其中前20 条数产品,用户的等级从高到低列出
我写的SQL语句
select products from A where name in ( select level from B order by level desc) limit 20;
感觉这种嵌套查询不对,如果用连接查询,该如何写呢?
SELECT a.products FROM b.level a LEFT JOIN b ON a.name = b.name ORDER BY b.level LIMIT 0,20