SELECT with keyword search

2

How to make a SELECT with specific fields and using LIKE %% in the same statement? something like:
SELECT TABLE_A.COLUMN1, TABLE_A.COLUMN2 FROM TABLE_A WHERE COLUMN2 LIKE 'A%' Home already tried this but does not return anything.

    
asked by anonymous 19.06.2015 / 17:50

2 answers

3

The SELECT command does not look bad to me. This is intended to select records where COLUMN2 has values beginning with the A uppercase letter. The LIKE syntax is simple:

  • % is a wildcard. Serves to represent 0, 1 or N characters
  • _ is a placeholder . Serves to represent 1 and only 1 any character

By using the A% pattern, we are conditioning the results to any value that starts with A , or just A

  • A OK
  • Andreia OK
  • André OK
  • arara NÃO OK
  • Monkey NÃO OK

To ignore the case, assuming the table or field is configured to be Case Sensitive , simply reduce both to one of the cases, for example:

SELECT * FROM TABELA WHERE LOWER(COLUNA) LIKE 'a%'

The wildcard can be repeated. For example, if we want to restrict to names that contain a A in any position:

LIKE '%a%'

An email verification (rudimentary):

LIKE '%_@_%._%'

With a minimum of 3 characters:

LIKE '___%'

And so on.

    
19.06.2015 / 18:09
0

Put the identifier Administrator.userName in the WHERE, so maybe that is why it is not identifying correctly

SELECT Administrator.userPass, Administrator.userName
FROM Administrator
WHERE Administrator.userName LIKE "c%"
    
19.06.2015 / 18:11