Skip to content
Advertisement

Finding a phone number by entering a string SQL

I want to find the phone number in the database by entry into the string, while I wrote this. But if, for example, the number starts with +3 and not only with +7. Any help would be welcome. in SQL I am newbie

For example, there is a Users table with a phone column. There are numbers starting at + 7, + 3. How can I display both options in one query?

SELECT * FROM workers WHERE phone LIKE ‘+7%’

SELECT * FROM workers WHERE phone LIKE ‘+3%’

how to combine this into one query? or does this answer the question “Finding a phone number by entering a string”

Advertisement

Answer

two approaches to consider:

SELECT * FROM workers WHERE phone LIKE '+7%' OR phone LIKE '+3%'

or

SELECT * FROM workers WHERE phone LIKE '+7%'
UNION
SELECT * FROM workers WHERE phone LIKE '+3%'
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement