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;
感觉这种嵌套查询不对,如果用连接查询,该如何写呢?

解决方案 »

  1.   

    SELECT a.products FROM a left join b on a.name = b.name order by b.level limit 0,20
      

  2.   

    SELECT a.products FROM a LEFT JOIN b ON a.name = b.name ORDER BY b.level LIMIT 0,20
      

  3.   

    select products from A,B where A.name=B.name order by B.level desc
      

  4.   

    如果还要读出level 要怎么写呢是不是
    SELECT a.products FROM b.level a LEFT JOIN b ON a.name = b.name ORDER BY b.level LIMIT 0,20
      

  5.   

    少了个from b SELECT a.products FROM a LEFT JOIN b b.level from b ON a.name = b.name ORDER BY b.level LIMIT 0,20
      

  6.   

    SELECT a.products,b.level FROM a LEFT JOIN b ON a.name = b.name ORDER BY b.level LIMIT 0,20
      

  7.   

    select a.name,b.level from tbl_a a left join tbl_b b on a.name=b.name  order by b.level desc limit 0,20
      

  8.   

      PHP 正在学习中,希望大家多多指教