# Write a SOQL query to fetch Accounts that have at least one related Contact (Inner Join / Semi-Join using WHERE Id IN (SELECT AccountId FROM Contact)).

**Topic:** Development · **Difficulty:** Easy · **Asked at:** Deloitte, Accenture, Infosys · **Tags:** soql, scenario, semi-join

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-soql-query-to-fetch-accounts-that-have-at-least-one-related-contact-inner-join-semi-join-using-where

## Answer

Use a semi-join: `WHERE Id IN (SELECT AccountId FROM Contact)`.

```soql
SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM Contact)
```
Only Accounts having at least one Contact are returned. The subquery must select a single Id/lookup field.

---
Source: ForceChallenges · last updated 2026-10-19
