SELECT on 2 MySql tables with PHP

1

I have a question when giving a select, because I have 3 tables, they are professionals, experiences, address.

Let's say I have a professional and this professional has more than 2 experiences. Is there any way to bring this information in a line, if not how can I do it in php, so that the name of the professional is not repeated.

Tables:

Professional:

id

name

surname

civil_status

Experiences:

id

charge

dt_entry

dt_said

professional_id

My select for now is like this

SELECT pro.id, pro.nome, exp.cargo
FROM Profissional pro
INNER JOIN experiencias exp ON exp.id_profissional = pro.id
WHERE pro.id = :algumacoisa GROUP BY pro.id

Example output

We have 1 registered professional with 2 positions.

ID             Nome                  Cargo           Cargo

1             romario            programador        Técnico

More or less, I know that the table name does not repeat itself, but if you have a solution, thank you.

    
asked by anonymous 29.09.2015 / 21:15

2 answers

3

I was able to solve this problem, I just used GROUP_CONCAT ();

It looks like this:

SELECT pro.id, pro.nome, GROUP_CONCAT(exp.cargo)
FROM Profissional pro
INNER JOIN experiencias exp ON exp.id_profissional = pro.id
WHERE pro.id = :algumacoisa GROUP BY pro.id

It brings all of this user's posts in a row just without repeating the name and comma-separated.

    
29.09.2015 / 22:30
0
SELECT pro.id,pro.nome,exp.id,exp.nome
   FROM Profissional pro, experiencias exp 
WHERE exp.id = pro.id and pro.id = :algumacoisa
    
29.09.2015 / 21:46