Page 1 of 1

Can I use OR in SELECT?

Posted: Sat Mar 17, 2007 5:39 pm
by SmokyBarnable
Is it possible to select from a table using or? For example if I have a form that asks for the customers email address or user id, can I create a query such as: SELECT A OR B FROM table... Is this syntax allowed?

Posted: Sat Mar 17, 2007 6:02 pm
by John Cartwright

Posted: Sat Mar 17, 2007 6:02 pm
by SmokyBarnable
Could I use or in WHERE?

Posted: Sat Mar 17, 2007 6:04 pm
by John Cartwright
try it first, ask later

Posted: Sat Mar 17, 2007 6:10 pm
by SmokyBarnable
What is more efficient..using or in SELECT or using or in WHERE?

Posted: Sat Mar 17, 2007 6:14 pm
by John Cartwright
I don't understand your question. The SELECT clause and the WHERE clause are two different parts of the query. In your case, you'd put it in the WHERE clause.

Posted: Sat Mar 17, 2007 7:56 pm
by SmokyBarnable
I did some research and discovered I need to consider precedence in the WHERE clause. I tried using parenthesis however when
testing it only works if person enters their email. When they enter their buyer_id it doesn't find the row.

Code: Select all

$buyersql = "SELECT DISTINCT (buyer_id), buyer_name, buyer_email, 
	buyer_countrycode, buyer_land, buyer_zip, buyer_city, buyer_street 
	FROM auction_details 
	WHERE auction_details.order_number =0 
	AND auction_details.email_sent =0
	AND (auction_details.buyer_email='".$email."' OR auction_details.buyer_id='".$email."')";
	$mybuyer = tep_db_query($buyersql);

Posted: Sat Mar 17, 2007 8:32 pm
by John Cartwright
I dont think $email belongs in the id column.