Hello ricksmart1977,
Thank you for contacting us. You will have to code this custom query based on your actual database setup, which can differ greatly.
Here is a link to a guide on how to "Select Data From a MySQL Database". It includes working examples to help you create a query.
We also have a guide on How to use PHP to connect to and retrieve data from MySQL, as part of our full tutorial series on Using PHP to create dynamic pages.
If you have any further questions, feel free to post the below.
Thank you,
John-Paul