A SELECT that pulls rows from a column (string;string)

Asked

Viewed 63 times

1

Well I need a SELECT that returns all the lines that contain the name "maria", I have in a column the values and I want a select that shows me all the lines that have the word "maria" in that column.

Example, in a given column I have the values:

1) (Joana;Rla;Josefa)

2) (Greece; Mary; Julia)

3) (maria;Carol;Jaqueline)

SELECT needs to return me the lines of 2 and 3 that possess "maria"

Need to do a filtering in php and list certain data of these lines

  • 1

    What have you ever tried to do ?

  • select * from cms_news Where Author like "%maria%", only it is not effective because it shows everyone that has the snippet maria in the name

  • 1

    And isn’t that what you need ? Because that’s what you’re talking about in the question! Look at this example I did on sqlfiddle

  • 1

    I’ll signal to close to ask, because if that’s all, you’re doing it right, unless you’re finding some problem, so edit your question and make a better description of your question or problem. Questions read What it means if a question is "closed" or "pending"?.

  • Already solved, I was wrong anyway. Thank you for the strength

  • 1

    Set the resolution Homi

  • 1

    Hello @Giovanyhenrique, I have a way that is possible to search column by column, but in SQL SERVER, which BD you are using?

  • The way I did was to put a character before and after the name of the person, so the sql of the post came out correct, example, instead of by "maria" I put ";maria;", and when I went to display I took the ";", since only I will see that it has the semicolons, so that’s fine.

Show 3 more comments

1 answer

1


From what I understand you have a varchar field and need to find in it, all names that contain a certain value, you can use the commands like plus %.

The operator LIKE is used in a clause WHERE to search for a specified pattern in a column. Example:

SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;

Another possibility to be explored is the use of the operator _. This setting any character, for example:

WHERE CustomerName LIKE '_r%'

It will look for any word with the r in the second position. It can be used several ways you can see more here.

Having said all these concepts, the way to solve your problem would be a select with like simple:

select * from TABELA where CAMPO LIKE '%maria%'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.