How to write a query if i want to fetch data ,the condition is like this-there are some account without contacts and there are some contacts without accounts.
The first question would be why, this sound like a standard Report to be set up Query wise this depends on how many data rows you will have but this sounds more for a batch then a standard query in regards to limits within collections.
Create one formula field on contact, lets name it account_name_formula__c wih return type text. In formula field, insert "account.Name" in advanced formula section and save.
then just fire the querry : select Name,account_name_formula__c from Contact where account_name_formula__c=null --> contacts with null accounts select Name,account_name_formula__c from Contact where account_name_formula__c!=null --> Accounts with contact
Query wise this depends on how many data rows you will have but this sounds more for a batch then a standard query in regards to limits within collections.
Create one formula field on contact, lets name it account_name_formula__c wih return type text. In formula field, insert "account.Name" in advanced formula section and save.
then just fire the querry :
select Name,account_name_formula__c from Contact where account_name_formula__c=null --> contacts with null accounts
select Name,account_name_formula__c from Contact where account_name_formula__c!=null --> Accounts with contact
Let me know if this is helpful
Cheers,
Muzammil bajaria