Good afternoon everyone

There are several tables, for example:

product table

id shop_id item_name item_qty 1 100 coca-cola 2 2 100 pizza 1 3 101 cheeseburger 5 4 102 pepsi 4 

buyers

  id shop_id email 1 101 test@test.ru 2 102 test@test.ru 3 103 test@test.ru 4 104 test@test.ru 

purchase statuses

  id shop_id status_st 1 100 not_cheked 2 101 not_cheked 3 102 not_cheked 4 103 not_cheked 

shopping information.

  id date summa method 100 2017-02-09 10$ bank 101 2017-02-09 10$ i-bank 102 2017-02-09 10$ bank 103 2017-02-09 10$ bank 

I need to combine them in approximately the following way:

  id date summa item_name status_st email 100 2017-02-09 10$ coca-cola, pizza not_cheked test@test.ru 

So that the goods with the same ID are connected in one line and plus everything combined with other tables.

I tried as follows:

 SELECT s.id, s.date, s.summa, s.method, s.language, b.email, GROUP_CONCAT(it.item_name SEPARATOR ';') item_name, sh.shelter_name, sh.url, st.status_st, st.status_md, st.status_end, st.status_last, st.photo FROM shop_info s LEFT JOIN shop_buyer b ON s.id = b.shop_id LEFT JOIN shop_shelter sh ON s.id = sh.shop_id LEFT JOIN shop_status st ON s.id = st.shop_id LEFT JOIN shop_items it ON s.id = it.shop_id ORDER BY s.id 

With this layout, I only get 1 line in which all the goods. I hope I understood clearly.

Help please, quite weak in mysql

  • four
    add group by without it all groups up to one line - Mike
  • Thanks, helped! - Alexander Reizan

0