0

Hello I am new to mySQL and i am having trouble trying extracting data from my db by using keywords. I have 2 columns (tags and categories). I have done this before using the LIKE '%keyword%' in my query. The problem is in the db i am using now each keyword is separated with a ';' i would like to know if it is possible to somehow separate each keyword by replacing the semi-colon with a space? Or if it's easier use the same query but instead of using '%' to separate i use semi-colons? sorry if its a newbie question but i am struggling hard with this and really need some help.

Thanks

2 Answers 2

1

You can replace semi-colon with space ( or any other ) with REPLACE function :

UPDATE MyTable SET tags = REPLACE(tags,';',' '), categories = REPLACE(categories,';',' ')
Sign up to request clarification or add additional context in comments.

Comments

0

The problem is in the db i am using now each keyword is separated with a ';' i would like to know if it is possible to somehow separate each keyword by replacing the semi-colon with a space? Or if it's easier use the same query but instead of using '%' to separate i use semi-colons?

Example table:

CREATE TABLE `test` (  
  `tags` varchar(255) NOT NULL,
  `categories`  varchar(255) NOT NULL  
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Sample data:

insert into `test` values ('tag', 'cat' );
insert into `test` values ('tag', 'cat1;cat2;cat3;' );

Example select:

select * from `test` where `categories` LIKE '%cat1;%';
+------+-----------------+
| tags | categories      |
+------+-----------------+
| tag  | cat1;cat2;cat3; |
+------+-----------------+
1 row in set (0.00 sec)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.