thinkphp子查询

实现一条语句:

SELECT provinceid,provincename from tsh_province where provinceid in(

SELECT DISTINCT gs_provinceid from tsh_greenschool)

 

 

thinkphp:

 $subquery=M('greenschool')->field('gs_provinceid')->group('gs_provinceid')->select(false);

$result=M('province')->fetchSql(true)->field('provinceid,provincename')->where('provinceid in '.$subquery)->select();
 
    	$subquery=M('greenschool')->distinct(true)->field('gs_provinceid')->select(false);

    	$plist=M('province')->field('provinceid,provincename')->where('countryid=1 and provinceid in '.$subquery)->order('provinceid')->select();

  

你可能感兴趣的:(thinkphp)