Remove Group_concat and list each one separately

Asked

Viewed 45 times

0

I want to remove group_concat to list each one separately, some hint?

SELECT
   U.login, 
   (SELECT Group_concat(AC.curso ORDER BY id ASC) 
    FROM   alunos_cursos AC 
           LEFT JOIN cursos C 
                  ON AC.curso = C.id 
    WHERE  AC.aluno = U.id 
           AND AC.disponivel = 1 


     AND AC.curso <> 9) CURSOS 
FROM   usuarios U 
Where NIVEL_ACESSO=0

Example:

Of

 LOGIN   CURSOS
    1     100, 112, 12, 43, 3
    2     9, 25, 6, 78, 44, 70

To

  LOGIN   CURSOS
    1     100
    1     112
    1     12
    1     43
    1     3
    2     9
    2     25
    [...]
  • 2

    Hello @Hiago. Ask your question in English pf. You are on Sopt.

  • Thanks @Joãomartins didn’t notice, I’m new on the platform.

1 answer

1

SELECT U.login,
      AC.course
  FROM users U
  INNER JOIN students_courses AC ON AC.student = U.id
  LEFT JOIN courses C ON AC.course= C.id
WHERE level_access = 0
  AND AC.avaliable = 1
  AND AC.course <> 9
ORDER BY U.login
  • Very well thought out, but it is not returning correctly. The student ID is coming incorrect, as if it were joining with another number. = / I’m trying to see where the mistake might be.

  • @Hiagomendes puts the description of the structures of the tables so that we can evaluate what would be the best solution. If possible with some sample data

  • I think putting the code in Portuguese will give you a better understanding. I didn’t put it in Portuguese because I didn’t realize it was Sopt. I’ll edit the Post and update the information. In this case, I am listing two tables where I take the student’s Registration and look for his course by the ID in another table.

  • @Hiagomendes in reality do not see as information that the id is "joining with another number" could proceed, after all the column is explicit in query

  • I will try to find out how to reverse this problem using your query as a basis. I have been trying for 8 hours already.

  • @Hiagomendes places the structure and sample data of his table that I make a fiddle to solve his problem

  • I don’t know if it’s allowed, but it wouldn’t hurt to ask. Would you have the possibility of doing a remote access to take a look? I don’t usually use phpmyadmin and I don’t mess with databases, I’m actually creating a way to use students' data on another platform.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.