Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use multiple left join join queries in mysql

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report