Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use multiple left join join queries in mysql

Shulou Source: shulou.com Published: 2022-05-31 22:12:59 10月02日 Update

In this issue, the editor will bring you about how to use multiple left join connection queries in mysql. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

When you need to join multiple tables when querying mysql, for example, to query the commodity table of an order, you need to query other information about goods. Other information is not in the commodity table of the order, and you need to join tables of other databases. But the condition for the connection is basically commodity ID. Give an error statement first (the nesting between queries is very inefficient):

SELECT A.order_id, A.wid, A.work_name, A.supply_price, A.sell_price, A.total_num, A.sell_profit, A.sell_percent, A.goods_id, A.goods_name, A.classify, B.gb_nameFROM (SELECT A.sub_order_id AS order_id, A.photo_id AS wid, A.photo_name AS work_name, A.supply_price A.sell_price, sum (A.num) AS total_num, (A.sell_price-A.supply_price) AS sell_profit, (A.sell_price-A.supply_price) / A.sell_price AS sell_percent, A.goods_id, A.goods_name B.goods_name AS classify FROM order_goods AS A LEFT JOIN (SELECT A.goods_id, A.parentid B.goods_name FROM test_qyg_goods.goods AS A LEFT JOIN test_qyg_goods.goods AS B ON A.parentid = B.goods_id) AS B ON A.goods_id = B.goods_id WHERE A.createtime > = '2016-09-09 00:00:00'AND A.createtime =' 2016-09-09 00:00:00'AND A.createtime

Tags: Query multiple goods analysis information content results orders professional size small and medium between rich in content that is efficiency articles more conditions knowledge articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi macOS Linux OPPO Reno Shulou Technology