Skip to content
Advertisement

query don´t show one result

i have this query:

SELECT asistencia.codAsistencia, asistencia.fecha, bonos.codBono, asistencia.estado, 
                                                  contratan.activo, contratan.codContrato, contratan.tiempoRestanteBono, asistencia.mensaje, users.nombre 
                                            FROM asistencia, users, bonos, contratan 
                                            WHERE asistencia.usuario = users.id 
                                            AND contratan.bono = bonos.codBono 
                                            AND asistencia.estado = 'pendiente' 
                                            GROUP BY asistencia.codAsistencia

i can show my result, but always don´t show all, i want to say that if my result it´s 3 my query show 2 when all my result have the same result. all data have state=”pendiente”

table user

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('nif');
        $table->string('nombre');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->string('direccion')->nullable();
        $table->string('perfil')->default('usuario');
        $table->integer('telefono')->nullable();
        $table->rememberToken();
        $table->timestamps();
    });
}
table bonos

public function up()
{
    Schema::create('bonos', function (Blueprint $table) {
        $table->increments('codBono');
        $table->string('tipo',20);
        $table->integer('minutos')->unsigned();
        $table->Double('precio',5,2);
        $table->timestamps();
    });
}

table asistencia

public function up()
{
    Schema::create('asistencia', function (Blueprint $table) {
        $table->increments('codAsistencia');
        $table->dateTime('fecha');
        $table->longText('mensaje');
        $table->bigInteger('usuario')->unsigned();
        $table->string("estado", 20)->default("pendiente");
        $table->timestamps();



        // hacemos la insercción aquí ya que la tabla debe estar creada
        DB::table('bonos')->insert([
            ['tipo' => '1/2H', 'minutos' => '30', 'precio' => '20'],
            ['tipo' => '1H', 'minutos' => '60', 'precio' => '40'],
            ['tipo' => '5H', 'minutos' => '300', 'precio' => '175'],
            ['tipo' => '10H', 'minutos' => '600', 'precio' => '330'],
            ['tipo' => '24H', 'minutos' => '1200', 'precio' => '600'],
        ]);



        $table->foreign('usuario')->references('id')->on('users');
    });
}

table actuacion

 public function up()
{
    Schema::create('actuacion', function (Blueprint $table) {
        $table->increments('codActuacion');
        $table->dateTime('fecha');
        $table->Integer('tiempoEmpleado');
        $table->Integer('asistencia')->unsigned();


        $table->foreign('asistencia')->references('codAsistencia')->on('asistencia');

    });
}

table contratan

public function up(){
    Schema::create('contratan', function (Blueprint $table) {
        $table->increments('codContrato');
        $table->Integer('bono')->unsigned();
        $table->Integer('tiempoRestanteBono')->unsigned();
        $table->tinyInteger('activo')->default('0');
        $table->bigInteger('usuario')->unsigned();


        $table->foreign('usuario')->references('id')->on('users');
        $table->foreign('bono')->references('codBono')->on('bonos');
    });
}

i attached my migration for you can show mi ralation

Advertisement

Answer

I resolve my problem adding condition

AND contratan.activo = 0 or contratan.activo = 1 
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement