从isp\u acknows i left join pdfreads p on i.id=p.ips\u acknow\u id中选择distinct i.filename“filename”,p.ips\u acknow\u id“isp 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();
1条答案
按热度按时间olmpazwi1#
db::table('isp\u acknows')->join('pdfreads','isp\u acknows.id','=','pdfreads.isp\u acknow\u id')->select('isp\u acknows.filename','isp\u acknows.filedisplayname','isp\u acknows.fileversion','isp\u acknows.privilege','isp\u acknows.rements')->其中('pdfreads.user\u id',$id)->分页(1000);