-- 1 -- RECHERCHE
SELECT -- DISTINCT p.codeGcAssureur 
	p.*
FROM police p
INNER JOIN emission e ON (e.idPolice=p.id)
INNER JOIN quittance q ON ((e.idPolice=p.id) AND (e.id=q.idEmission))
WHERE e.codeTypeAvenant='QTM'
-- AND p.codeGcAssureur='SIDAM'
AND p.libellePolice LIKE '%tsp%'
-- AND p.codeGcAssureur='GNA'

SELECT p.*
FROM police p
-- INNER JOIN emission e ON (e.idPolice=p.id)
WHERE p.libellePolice LIKE '%BABU%'
-- AND e.codeTypeAvenant='QTM'
 
SELECT e.*
FROM police p
INNER JOIN avenant e ON (e.idPolice=p.id)
WHERE p.codeGcAssureur='SIDAM'
-- AND e.codeTypeAvenant='QTM'


-- 2-DELETE

DELETE q
FROM police p
INNER JOIN emission e ON (e.idPolice=p.id)
INNER JOIN quittance q ON ((e.idPolice=p.id) AND (e.id=q.idEmission))
WHERE e.codeTypeAvenant='QTM'
AND p.id IN (168);
-- AND p.codeGcAssureur='GNA';


DELETE e
FROM police p
INNER JOIN emission e ON (e.idPolice=p.id)
WHERE e.codeTypeAvenant='QTM'
AND p.id IN (168);
-- AND p.codeGcAssureur='GNA';


DELETE e
FROM police p
INNER JOIN avenant e ON (e.idPolice=p.id)
WHERE e.codeTypeAvenant='QTM'
AND p.id IN (168);
-- AND p.codeGcAssureur='GNA';

SELECT * FROM avenant WHERE idPolice=168
-- reinitiliser le numero des avenants dans la table police / avenant