Last active
May 20, 2021 11:22
-
-
Save alvaro-prieto/3ee0299022ade5bcd6bd8f3d1a335ac1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Las relaciones left y right son permitidas. Normalmente no tendremos que tocar el ON | |
//No obstante : | |
//si tenemos condiciones adicionales del on del join, se ponen como 3er parametro | |
//de relación. La relación primaria de las tablas no hay que ponerla, porque ya la pone | |
//el framework | |
/* | |
select distinct U.id, T.clase, T.estado1 as leido | |
from usuarios U | |
left join tareas T | |
on T.idusuario = U.id and (T.Clase = 'DataControl' and estado1=0) | |
where U.idcentro = 5 and U.activo = 1 ; | |
*/ | |
$Usuario = new Usuario(); | |
$Usuario->añadeFiltro("id != {$this->quid->idusuario()} and activo = 1 and idcentro= {$this->quid->idcentro()}"); | |
$Usuario->relacion("Tareas","left", "clase = '{$tipo}' and estado1=0"); | |
$listado = $Usuario->Tareas->lista("distinct Usuario.id as idusuario, Tareas.clase, Tareas.estado1 as leido"); | |
var_dump($listado); | |
// Otro posible uso del distinct, es directamente en un campo | |
$s .= $this->insertaTabla( | |
[ | |
"campos" => [ | |
"nombre" => ["campo" => "distinct(nombre)", "rotulo" => "Iniciativa", "tipo" => "texto", "soloLectura" => true], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment