开发者

Join MYSQL tables and sort by two fields?

开发者 https://www.devze.com 2023-02-12 15:41 出处:网络
I\'m having a problem sorting my tables in MYSQL. I have my tables setup like this: Order_details Order_ID

I'm having a problem sorting my tables in MYSQL.

I have my tables setup like this:

Order_details

  • Order_ID
  • shipping_cost
  • printed

Product_details

  • ID
  • Order_ID
  • SKU_location

I want to SELECT all orders WHERE printed = FALSE but also sort by the shipping costs and THEN by the SKU_location

How can I join the tables into one query s开发者_如何学JAVAo it sorts by shipping_cost and SKU_location where printed = false?


You can do an implicit JOIN in the following way:

SELECT * 
FROM Order_details od
JOIN Product_details pd
ON od.Order_ID = pd.Order_ID
WHERE od.printed = FALSE
ORDER BY od.shipping_cost, pd.SKU_location

The text following each table renames the table for easy reference in the later parts of the query (i.e. the code "Database.Long_Table_Name ltn" renames the table to "ltn")

0

精彩评论

暂无评论...
验证码 换一张
取 消