Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select where LIKE from multiple columns

Author  Topic 

smcallister
Starting Member

15 Posts

Posted - 2008-05-20 : 10:32:22
I am using mySQL and the following query works fine:

SELECT * from listings where name LIKE \"%$trimmed%\" order by name";

and so does this query:

SELECT * from listings where keywords LIKE \"%$trimmed%\" order by name";

however, I can't seem to combine the two with an OR statement as this query only returns the results from the first LIKE column

select * from listings where name LIKE \"%$trimmed%\" or keywords LIKE \"%$trimmed%\" order by name

I want to be able to search both columns and return a row if the NAME column or the KEYWORDS columns contains a string.

smcallister
Starting Member

15 Posts

Posted - 2008-05-20 : 10:50:29
SELECT * from listings where CONCAT_WS('',name,keywords) LIKE \"%$trimmed%\" order by name

this works but I'm not sure if it's the correct way of doing it. I am simply concatenating the two columns and searching through that concatenation.
Go to Top of Page
   

- Advertisement -