Need help to get the max in forien key

Hi every body

any body can help me to get the max record for a forien key
I have two tables

customer (ID, … info)
and Bills (ID, Customer_id, Info)

I want to get a customer information and the last bill record

I write this query


select c.id,c.info, b.info from customer c 

JOIN (
SELECT * 
FROM   Bills
WHERE  id=(SELECT MAX(id) FROM Bills where customer_id = 1)
) as b
ON b.customer = c.id

where c.id=1

is there any way to customize this query ?

SELECT c.id
     , c.info
     , b.info 
  FROM ( SELECT customer_id 
              , MAX(id) AS latest
           FROM Bills 
         GROUP
             BY customer_id ) AS x
INNER
  JOIN Bills AS b
    ON b.customer_id = x.customer_id
   AND b.id = x.latest
INNER
  JOIN customer AS c
    ON c.id = b.customer_id
 WHERE c.id = 1

it’s a very complex query for me
it help me

many thanks :slight_smile: