PurposeHealthcare provision in the United Kingdom (UK) falls primarily to the National Health Service (NHS) which is free at the point of access. In the UK, there is currently no national marker to identify military veterans in electronic health records, nor a requirement to record it. This study aimed to compare the sociodemographic characteristics and recorded mental health diagnoses of a sample of veterans and civilians accessing secondary mental health services.MethodsThe Military Service Identification Tool, a machine learning computer tool, was employed to identify veterans and civilians from electronic health records. This study compared the sociodemographic characteristics and recorded mental health diagnoses of veterans and civilians accessing secondary mental health care from South London and Maudsley NHS Foundation Trust, UK. Data from 2,576 patients were analysed; 1288 civilians and 1288 veterans matched on age and gender.ResultsDepressive disorder was the most prevalent across both groups in the sample (26.2% veterans, 15.5% civilians). The present sample of veterans accessing support for mental health conditions were significantly more likely to have diagnoses of anxiety, depressive, psychosis, personality, and stress disorders (AORs ranging 1.41–2.84) but less likely to have a drug disorder (AOR = 0.51) than age- and gender-matched civilians.ConclusionVeterans accessing secondary mental health services in South London had higher risks for many mental health problems than civilians accessing the same services. Findings suggest that military career history is a key consideration for probable prognosis and treatment, but this needs corroborating in other geographical areas including national population-based studies in the UK.Supplementary InformationThe online version contains supplementary material available at 10.1007/s00127-022-02411-x.