Home  >  Q&A  >  body text

Record query under partial value conditions - SQL skill sharing

I have a table named zipcode which has a column named code. The Code column contains the prefix of the zip code, for example

395
453
302
1203
12

I want to write a SQL query that checks if the provided zipcode matches a certain value in the table. (Similar to isValid)

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

Valid entered postal code

395004
395152
3952
1256

Can anyone help me? Thanks

P粉588660399P粉588660399154 days ago373

reply all(1)I'll reply

  • P粉442576165

    P粉4425761652024-04-07 13:51:08

    Simple SQL query:

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

    Reference:SQL - Query if a string contains part of a column value

    reply
    0
  • Cancelreply