Problem with mysql join query

I have 2 tables
1) "products" with fields (productid PK, name, description, price)
2) "sales" with fields (salesid PK, salestime, productid, customername, customeremail, status)

I need to display data in table format as

Identifier Customer Address Billing Status

For this, I use the following query

SELECT s.salesid, p.name, p.price, s.customername, s.customeremail, s.status 
FROM sales s 
LEFT JOIN products p ON s.productid = p.productid 
ORDER BY salestime DESC 
LIMIT 0, 15 

Is there a way to optimize this query to work faster?

+3
source share
3 answers

Do you have matching indexes in tables?

See CREATE INDEX Syntax and How MySQL Uses Indexes

+2

, . , .

RDMS, , , ( oroductid)

0

Request is ok. Try indexing productidin both tables as well salestime.

0
source

Source: https://habr.com/ru/post/1776612/


All Articles