Question - Query based on WHERE OR

Поиск
Список
Период
Сортировка
От Mike Poe
Тема Question - Query based on WHERE OR
Дата
Msg-id 1168479517.968077.279130@p59g2000hsd.googlegroups.com
обсуждение исходный текст
Ответы Re: Question - Query based on WHERE OR  ("John D. Burger" <john@mitre.org>)
Re: Question - Query based on WHERE OR  (SCassidy@overlandstorage.com)
Re: Question - Query based on WHERE OR  (Ragnar <gnari@hive.is>)
Список pgsql-general
I'm a rank newbie to Postgres & am having a hard time getting my arms
around this.

I'm trying to construct a query to be run in a PHP script.  I have an
HTML form were someone can enter either a last name or a social
security number & then query the database based on what they entered.

My query looks like this:

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?

Thank you.
Mike


В списке pgsql-general по дате отправления:

Предыдущее
От: chwy_nougat@yahoo.com
Дата:
Сообщение: Re: remove embedded carriage returns
Следующее
От: Christopher Browne
Дата:
Сообщение: Re: Autovacuum Improvements