'select where' using multiple columns.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

'select where' using multiple columns.

Rob Kirkbride
Hi,

I've googled around for this but can't see a decent way of doing this :

I've got a persons name which is being stored say in 3 columns :-  
Title, Forename_1, Forename_2, Surname. I want to allow a search say for
'John Smith'. Problem is I can't just break it up into forename and
surname because I won't also know.
Is there a way to do something like a
'select * where forename_1,forename_2,surname like '%String%'   ??

Thanks for any help. Apologies if its a FAQ.

Rob


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Reply | Threaded
Open this post in threaded view
|

Re: 'select where' using multiple columns.

Ian Johannesen
Hi.

Rob Kirkbride wrote:

> I've googled around for this but can't see a decent way of doing this :
>
> I've got a persons name which is being stored say in 3 columns :-
> Title, Forename_1, Forename_2, Surname. I want to allow a search say for
> 'John Smith'. Problem is I can't just break it up into forename and
> surname because I won't also know.
> Is there a way to do something like a
> 'select * where forename_1,forename_2,surname like '%String%'   ??
>
> Thanks for any help. Apologies if its a FAQ.
SELECT * FROM table WHERE forename_1 || ' ' || forename_2 || ' ' ||
surname LIKE '%String%';

--
Digitally Yours,

Ian Johannesen
web: http://perlpimp.dk/
msn: [hidden email]
cel: +45 31 13 73 76

smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: 'select where' using multiple columns.

DaQ-2
In reply to this post by Rob Kirkbride


RK> Hi,

RK> I've googled around for this but can't see a decent way of doing this :

RK> I've got a persons name which is being stored say in 3 columns :-  
RK> Title, Forename_1, Forename_2, Surname. I want to allow a search say for
RK> 'John Smith'. Problem is I can't just break it up into forename and
RK> surname because I won't also know.
RK> Is there a way to do something like a
RK> 'select * where forename_1,forename_2,surname like '%String%'   ??

RK> Thanks for any help. Apologies if its a FAQ.

RK> Rob


RK> ---------------------------(end of broadcast)---------------------------
RK> TIP 5: don't forget to increase your free space map settings

Try this way:

select * .... where forename_1||' '||forename_2||' '||surname like '%String%'

or

select * .... where forename_1||' '||forename_2||' '||surname~'String'

DAQ


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq
Reply | Threaded
Open this post in threaded view
|

Re: 'select where' using multiple columns.

Hélder M. Vieira
In reply to this post by Rob Kirkbride

> Is there a way to do something like a
> 'select * where forename_1,forename_2,surname like '%String%'   ??


You could try the following, but it won't get a medal for performance...

SELECT * FROM xpto WHERE forename_1 LIKE '%String%' OR forename_2 LIKE
'%String%' OR surname LIKE '%String%'



Helder M. Vieira



---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
Reply | Threaded
Open this post in threaded view
|

Re: 'select where' using multiple columns.

Rob Kirkbride
In reply to this post by Ian Johannesen
Ian Johannesen wrote:

>Hi.
>
>Rob Kirkbride wrote:
>  
>
>>I've got a persons name which is being stored say in 3 columns :-
>>Title, Forename_1, Forename_2, Surname. I want to allow a search say for
>>'John Smith'. Problem is I can't just break it up into forename and
>>surname because I won't also know.
>>Is there a way to do something like a
>>'select * where forename_1,forename_2,surname like '%String%'   ??
>>
>>    
>>
>SELECT * FROM table WHERE forename_1 || ' ' || forename_2 || ' ' ||
>surname LIKE '%String%';
>
>  
>
Thanks for the quick response. I've tried that and it works fine. Thanks
a lot and thanks to Daq and Helder.

Rob

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend