Pattern Searching in UserDefined Column name

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
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Pattern Searching in UserDefined Column name

Post by anjanesh »

Any workaround for this ?

Code: Select all

SELECT *,CONCAT(FirstName,' ',MiddleName,' ',LastName) AS FullName FROM People WHERE FullName LIKE '%something%'
Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

can you explain a bit more?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

I want to search for something in FullName - which is FirstName, MiddleName and LastName combined. But it wont work. Instead I've to to do :

Code: Select all

FirstName LIKE %something% OR MiddleNameName LIKE %something% OR LastName LIKE %something%
I was hoping to have it done easier by just giving FullName
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

maybe...

Code: Select all

SELECT * FROM table WHERE CONCAT_WS(' ', FirstName, MiddleName, LastName) LIKE '%something%'
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Yes that works - but I need somehow to have the user defined column for that query FullName to be searched. Im using this in a basic search engine of mine.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can create the column seperately..
Post Reply