thinkphp 两张表关联查询 where(wholesal

2019-02-14  本文已影响0人  一位先生_

参考:   https://www.cnblogs.com/drizzlewithwind/p/9299129.html

有三种方法:

1.SELECT*FROM    CallWHEREphone_numberNOTIN(SELECTphone_numberFROM Phone_book)2.SELECT*FROM  CallWHERENOTEXISTS  (SELECT*FROM  Phone_book

  WHEREPhone_book.phone_number= Call.phone_number)3.SELECT*FROM  CallLEFTOUTERJOIN Phone_Book

  ON(Call.phone_number= Phone_book.phone_number)

  WHEREPhone_book.phone_numberISNULL

thinkphp 两张表关联查询  where(wholesaler.id = info.wholesaler_id) 查询在另一张表中不存在的数据

//处理数据

if(empty($page)){//判断页数是否为空

    $page = 1;

}

$page_num = 10;//每页显示条数

$page_start = ($page - 1) * $page_num;//数据开始

$data = M('user_wholesaler as wholesaler')

    ->where('NOT EXISTS (SELECT * FROM armarium_fr_wholesaler_info as info WHERE wholesaler.id = info.wholesaler_id)')

    ->field('wholesaler.id,wholesaler.enterprises_name,wholesaler.contacts,wholesaler.mobile,wholesaler.add_time')

    ->order('wholesaler.id desc')

    ->group('wholesaler.id')

    ->limit($page_start, $page_num)

    ->select();

上一篇下一篇

猜你喜欢

热点阅读