Return two results from same column

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Return two results from same column

Post by phpScott »

Im trying to write a mysql query where I want to return a result of two possible out comes as in

select propType from sites where propType='$propType' or propType='*'

where propType=BB

I would want returned all results that would have BB in the propType column as well as * in the propType column.

Any ideas without having to make two queries to the db

phpScott
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

take a look at 6.3.2.1 String Comparison Functions (mysql-manual)
you can use logical operands in WHERE clauses similar to PHP
SELECT .... WHERE cond1 OR cond2 is valid
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can also use the IN keyword (equivalent to lots of OR statements):

Code: Select all

SELECT propType FROM sites WHERE propType IN('$propType','*')
http://www.mysql.com/doc/en/Comparison_Operators.html

Mac
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

thanks

Post by phpScott »

thanks alot twigletmac :D :D that did the trick just nicely.
Much graditude.

phpScott
Post Reply