K
K
khodos_dmitry2018-03-13 09:46:58
MySQL
khodos_dmitry, 2018-03-13 09:46:58

Why is there a selection twice in a SQL query?

SELECT GROUP_CONCAT(CONCAT('<img class=\"ps-icon\" title =\"', 
    IF(`cpl_method_get`.`name` = `cpl_method_get`.`group`, `cpl_method_get`.`group`, CONCAT(`cpl_method_get`.`group`, ' (', `cpl_method_get`.`name`, ')')),
    '\" src=\"/img/ps/icon/', `cpl_method_get`.`img`, '.png\" >') SEPARATOR ' ') as `method_get` 
    FROM `cpl_mfo` JOIN `cpl_mfo-method_get` ON `cpl_mfo`.`name` = `cpl_mfo-method_get`.`mfo` JOIN `cpl_method_get` ON `cpl_mfo-method_get`.`method_get` = `cpl_method_get`.`name` JOIN `cpl_mfo_loans` ON `cpl_mfo_loans`.`mfo_id` = `cpl_mfo`.`id`

In method_get , all values ​​are fetched four times.
If you remove
JOIN `cpl_mfo_loans` ON `cpl_mfo_loans`.`mfo_id` = `cpl_mfo`.`id`

then everything is fine.
You can see what is selected here: https://credits-pl.ru/test/
Tables:
cpl_mfo
5abd0550b9df0347879689.png
cpl_mfo_loans
5abd056cf371c020232695.png
cpl_method_get
5abd05855ca4a496940709.png
cpl_mfo-method_get
5abd059c4e90e635978001.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
justpusher, 2018-04-02
@justpusher

Your mfo "E-Cabbage" corresponds to 4 entries in cpl_mfo_loans.
This means that after the last join you will have 4 lines for E-Cabbage, in which the fields of all tables except cpl_mfo_loans will be the same. You concatenate them with group_concat, so you end up with the same thing 4 times. I advise you to remove group_concat and put SELECT *, then it will be clearer to you what data is there.
PS for the future: lay out the structure of tables and dumps in the form of SQL queries (CREATE TABLE, INSERT), it is very difficult to understand by eye screenshots.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question