选择DISTINCT i.filename“文件名”,p.ips_acknow_id“ ISP确认ID” 来自isp_acknows i左联接pdfreads p ON i.id = p.ips_acknow_id
我也可以通过联接来做到这一点,但是我需要这种格式来提高性能。
Note:
1. isp_acknows table
Schema::create('isp_acknows', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->string('filename')->nullable();
$table->string('filedisplayname')->nullable();
$table->string('privilege')->nullable();
$table->string('fileversion')->nullable();
$table->string('remarks')->nullable();
$table->softDeletes();
});
2. pdfreads Table
Schema::create('pdfreads', function (Blueprint $table) {
$table->id();
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->unsignedInteger('ips_acknow_id');
$table->unique(['user_id','ips_acknow_id']);
$table->timestamps();
答案 0 :(得分:0)
DB :: table('isp_acknows') -> join('pdfreads','isp_acknows.id','=','pdfreads.isp_acknow_id') ->选择('isp_acknows.filename','isp_acknows.id','isp_acknows.filedisplayname','isp_acknows.fileversion', 'isp_acknows.privilege','isp_acknows.remarks')-> where('pdfreads.user_id',$ id) -> paginate(1000);