[SOLVED] SQL – Query to find records that contain part of the value

Issue

I have table zipcode which has a column called code. The Code column contains the prefix of zipcodes like

395
453
302
1203
12

I want to write an SQL query that checks if the provided zipcode matches one of the values in the table. (Something like isValid)

I want to avoid writing all zip codes in the database.

Valid Input zipcode

395004
395152
3952
1256

Can anyone help me? Thanks

Solution

simple sql query:

select * 
from zipcode 
where '395004' LIKE CONCAT(code,'%'); 

references: SQL – Query to find if a string contains part of the value in Column

Answered By – Protap Singh

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.