> I am building a user search engine. Now I do not know how to gett
> a mandatory field and a voluntary field
> For example I would like to get all female users and those who are from
> canada.
> The results should show all users who are female regardless of nationality
> But it should also show all users from canada.

ok... if the second field is not mandatory... you should not include it in
the where clause... the select will show all the rows regardless the value
in this field...

> How would this look like?
> FROM table
> WHERE sex=1 AND country='CA'

    SELECT *
      FROM table
      WHERE sex = 1

it will show all the rows...

== relevance ??

ok... if you want to show the Sex= 1 and country='CA' rows first... may be
you can use an UNION, maybe something like this...

  FROM table
  WHERE sex = 1 and country = 'CA'
  FROM table
  WHERE sex = 1 and country <> 'CA'

... or define a calculated field for these "relevance"... and order the
results by this value...

SELECT (sex = 1 AND country = 'CA') AS relevance, sex, country
  FROM table
  WHERE sex = 1

... note the relevance includes all the fields... and the where just the
mandatory conditions... the order must be DESC, because the "relevance" is 1
if the two conditions are match... and 0 if not

== is this the problem ??

if not... may be you are intereseted in different JOIN and UNION clauses...
may be a LEFT JOIN or similar


PHP Database Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to