+ Start a Discussion
sampath pallisampath palli 

Can i give more than one field in where condition in SOQL

I have an requirement that i need to retrive both name and password data from sobjecct which are given in vf page . I have write a soql query in apex controller like this way but it is working please suggest me 
select Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rname,Password__c=:pwd;

Thanks in advance
Best Answer chosen by sampath palli
ShivaKrishna(Freelancer)ShivaKrishna(Freelancer)
Hi there,

select Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rname,Password__c=:pwd;

where clause doesnot support "," and you should use logical operators (AND , OR etc..) depends on your criteria.

you can use like below,

select Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rname AND Password__c=:pwd;

let me know, if it helps you or need any help :)
shiva.sfdc.backup@gmail.com

 

All Answers

venkat-Dvenkat-D
You need to use AND parameter
[select Rum_Name__c,Password__c from Registartion__c where (Rum_Name__c = :rname and Password__c=:pwd)]
Mahesh DMahesh D
Hi Sampath,

Please find the below query:
 
List<Registartion__c> regList = [Select Id, Name, Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rname AND Password__c=:pwd];
Map<Id, Registartion__c> regMap = new Map<Id, Registartion__c>([Select Id, Name, Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rname AND Password__c=:pwd]);

You can either way, based on your requirement.

Also find the below information for your reference and understanding of SOQL.

https://developer.salesforce.com/docs/atlas.en-us.200.0.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_conditionexpression.htm

https://developer.salesforce.com/trailhead/en/apex_database/apex_database_soql

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_examples.htm

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL.htm



Please do let me know if it helps you.

Regards,
Mahesh
ShivaKrishna(Freelancer)ShivaKrishna(Freelancer)
Hi there,

select Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rname,Password__c=:pwd;

where clause doesnot support "," and you should use logical operators (AND , OR etc..) depends on your criteria.

you can use like below,

select Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rname AND Password__c=:pwd;

let me know, if it helps you or need any help :)
shiva.sfdc.backup@gmail.com

 
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
Try like below code.
 
list<Registartion__c>   result=[select Rum_Name__c,Password__c from Registartion__c where Rum_Name__c = :rname and Password__c =:pwd ];
		if(result.size() > 0 )
		{
			// Welcome
		}
		else
		{
			ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Invalid Password'));
		}

 
sampath pallisampath palli
Thank u all for ur reply I solved my problem