Having a one-to-many relation, I am trying to get records in the accounts
table where only one record exists in the accounts_prop
table.
I have the following query, but it does not do the desired. The query returns records with more records in the accounts_prop
table.
select *
from `accounts`
where exists (
select *
from `accounts_prop`
where `accounts`.`account_id` = `accounts_prop`.`account_id`
and `von` >= '2017-08-25'
having count(account_id) = 1
) limit 3
Best Answer
Setup sample data:
Sample data joined together:
Proposed query:
Here's a dbfiddle for the above.