Querying RG in database ignoring scores

4

I have a mysql database where I need to make a comparison of registered RGs with another one provided by the user through an input, to see if the same RG is already registered in the database.

The problem is that since you have records with scores in RG and others with no scores, there is no default. In this case, I thought of taking the scores I get from the input and compare with what I have in the database, by my SQL, but for this I need to ignore the scores that I already have in the RG column in my bank.

How can I do this in my SQL?

Note to the Portuguese: RG (General Register) is the official identity document in Brazil. The numbering format varies from state to state, and this generates a number of problems, including the ease of Brazilian citizens having irregularly different RGs in different states. There was a project to unify the system by exchanging the RG for the RIC, a new standardized format, but unfortunately the project was suspended. More details on #

    

asked by anonymous 29.10.2014 / 22:02

1 answer

10

You can use the REPLACE function of MySQL to replace the dots and dashes for nothing:

SELECT ...
FROM tabela
WHERE REPLACE(REPLACE(coluna, '.', ''), '-', '') = '123456789'

Important: Second #

    
29.10.2014 / 22:20