Can I use OR in SELECT?
Moderator: General Moderators
- SmokyBarnable
- Forum Contributor
- Posts: 105
- Joined: Wed Nov 01, 2006 5:44 pm
Can I use OR in SELECT?
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?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- SmokyBarnable
- Forum Contributor
- Posts: 105
- Joined: Wed Nov 01, 2006 5:44 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- SmokyBarnable
- Forum Contributor
- Posts: 105
- Joined: Wed Nov 01, 2006 5:44 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- SmokyBarnable
- Forum Contributor
- Posts: 105
- Joined: Wed Nov 01, 2006 5:44 pm
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.
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);- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: