View Single Post

   
  #2 (permalink)  
Old 04-09-2008, 02:20 PM
John D. Burger
 
Posts: n/a
Default Re: Question - Query based on WHERE OR

Mike Poe wrote:

> SELECT foo, baz, bar FROM public.table WHERE lastname ~*
> '$lastname' OR ssn='$ssn'"
>
> I need to leave the last name a wildcard in case someone enters a
> partial name, lower case / upper case, etc.
> I want the SSN to match exactly if they search by that.
> The way it's written, if I enter nothing for the last name, it
> returns all rows, regardless of what I enter for the ssn.
> I understand why it happens, but what can I do to return the
> desired results?


How about:

SELECT foo, baz, bar FROM public.table
WHERE ('$lastname' != '' and lastname ~* '$lastname') OR ssn='$ssn'";

Or perhaps some more general condition for "empty" lastname parameters.

- John Burger
MITRE

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org/

Reply With Quote