INNER JOIN does not return all records

Asked

Viewed 57 times

1

Talk people, good morning.

I have two tables in my bank (client and phone), where some clients have several records and others none. Initially I was having trouble "nesting" all the phone table records on the same line, but I already solved according to @Motta’s tip, however, I came up with another problem: The records of the client table that have no relationship in the phone table are not returned and I need to make them all be displayed (with or without relationship). It is possible to do this in the same query?

Bench:

Client (ID | NAME) Telephone (ID | FK_CLIENTE | NUMBER)

SQL:

SELECT DISTINCT c.`id`, c.`nome`, GROUP_CONCAT(DISTINCT t.`numero` ORDER BY t.`id` ASC) AS `telefone` FROM `cliente` AS c INNER JOIN `telefone` AS t ON t.`fk_cliente` = c.`id` GROUP BY c.`id`
  • Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of this. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English.

  • https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.html#function_group-Concat

  • @Motta Thanks for the feedback, I have already implemented this way. Now I have another question. I’ll edit my question to be clearer and more specific.

  • Exchange the INNER JOIN for LEFT OUTER JOIN. It will bring all customers, even those who have no phone associated.

  • @anonimo thanks for the feedback, solved the issue. I knew I was faltering about something in the instruction.

No answers

Browser other questions tagged

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