The MySQL has tables with customers, vendors, and customer and vendor addresses. And there is a table of all orders in which suppliers, customers and addresses id are stored. How to write a query to get all the values ​​from all tables and display all orders? Those. so that instead of aydishnikov from the table, the values ​​from the corresponding tables are substituted. Suppose the customer , seller , address and orders tables. In orders there is customer_id,seller_id,address_id . And it is necessary that when select * from orders instead of id in the output, substitute the values ​​of these IDs - names, names, addresses.
ps writing on php

    1 answer 1

    To solve your problem, you must use JOIN

    SQLFiddle code

    UPD 1: For some unknown reason, I can no longer write comments. Check the data types so that it doesn’t happen that the query compares for example text addresses (varchar) with id (int) - this may be one of the reasons why you have half the records missing. Or rather, dump the dump table structures on pastebin.com . The solution is somewhere near the banal error, you need to understand where. Yes, by dumping the tables it will be possible to raise them to SQLFiddle and already look specifically at the queries.

    • Not that. All orders are not displayed. Filters for some reason. It is necessary that several joins are not a condition for filtering, but replace aydishniki with appropriate values. - Zepp
    • Well, telepaths are all on vacation ... Show the request, we will look more detailed. - Opalosolo
    • one
      > It is necessary that several joins are not a condition for filtering, but replace aydishniki with appropriate values. @Zepp - you seem to be poorly aware of what is happening in the request. The request does not indicate a filtering condition, but a condition for “gluing” tables by id records - Opalosolo
    • one
      @Zepp - You have two fields that have the same name in two different tables, give the fields aliases. c.name,s.name заменить на c.name customer_name, s.name seller_name What did you get from this request? some data is not enough? Perhaps for any keys you do not have enough records in other tables, do you allow such a situation? - Opalosolo
    • one
      offtopic : the names of the tables you have in the plural, then in the singular, you already decide =) - Opalosolo