MySQL:如何从表中获取指定值的某些列?

时间:2014-04-18 17:40:36

标签: php mysql sql

我有2个名为learning_plan和tbl_user的表。我想这样做:

$qry=Query("SELECT user_name,user_family,coach_code FROM tbl_user WHERE user_level=2");
    while($result=mysql_fetch_array($qry))
     {
       $qry1=Query("SELECT * FROM learning_plan WHERE coach_code=".$result['coach_code']);
         while($result1=mysql_fetch_array($qry1))
           {

           }
     }

所以我希望在第二个查询时可以获得具有这些值的列(!= 1和< 5)

非常感谢你

1 个答案:

答案 0 :(得分:2)

为什么不使用JOIN只使用一个查询:?

 SELECT user_name,user_family,coach_code,t2.* 
 FROM tbl_user t1
 INNER JOIN learning_plan t2 ON t2.coach_code = t1.coach_code 
 WHERE t1.user_level=2