1
I’m doing a query in two tables (students and users) and picking up the id, name and email values. Right after I do a Union between them. However, I wish there were no lines with duplicate values for the email field. I need these values because from the user’s choice the collaborative table_project will have the foreign keys fk_student or fk_user filled. The email field is for differentiating lines, because although they are different tables the id can be the same. This query is to feed a Select Multiple, where the user will tell who are the employees who will participate in the project.
Consultation
$alunos = DB::table('alunos')->where('status','Ativo')->select('email', 'nome', 'id');
$usuarios = DB::table('users')->where('status','Ativo')->select('email', 'nome', 'id');
$colaboradores = $alunos->union($usuarios);
View
{!! Form::select('colaboradores[]', $colaboradores->pluck('nome'), null, array('class' => 'form-control', 'multiple'=>'true')) !!}
Tables
Users
ID | nome | email | funcao | ... |
Students
ID | nome | email | matricula | ... |
collaborations_project
ID | fk_projeto | fk_aluno | fk_usuario |
I need help on that part, because I’ve been having this problem for a few days.
Can post the table structure or just the sql query?
– Maurivan
I entered the information Maurivan.
– Overlooser
To select values from two tables you can use
join
or the intention and unite usingunion
.– Maurivan
A suggestion would be to give group by email. Test and post the result.
– DanZing
There is no relationship between the tables to do the Join.
– Overlooser
I believe that instead of using a "Join" to solve your problem, probably a restructuring of the tables would be better.
– Gabriel Katakura
A simpler solution is to create 2 relationship tables instead of 1, since they are different things because of what you said: one user_project and another project.
– Dudaskank