One query is a list, one query is details, how to better combine the two?

because of my interest, I am working on a web application in my spare time. At present, I have a big performance problem. I would like to consult you here. I hope you will not hesitate to give me your advice.

there are two tables, one is the exchange basic information table exhcangeinfo, has fields such as name,nick,url,twitter
the second table is the real-time trading volume table exchange has fields such as name,volume.

exchangeinfo has about 200 pieces of data, and the exchange table adds more than 200 pieces of data every 5 minutes to check transaction volume.

what I need now is a list of 20 records per page, which is the basic information of the exchange + the 12-hour trading volume of the exchange. At present, the stupid method I adopt is to get 20 records and then make a second query according to the name of the exchange. In fact, the performance is very poor.

select * from exchangeinfo where alive=True order by rank limit"+ start +","+ size

select volume from exchange where exchange.name =""+ name +" "order by timestamp DESC limit "+ limit

I think it should be optimized on the database side, but I don"t know how to do it.

Mar.20,2021
Menu