Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6895227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:52:54+00:00 2026-05-27T06:52:54+00:00

Assuming a Postgres Table containing zip as varchar(10) I want to get either all

  • 0

Assuming a Postgres Table containing zip as varchar(10) I want to get either all results matching a specific zip or extend my results with entries close to the queried one in case there are not enough results. Say:

A user searches for zip “56500” and my result-set returns 2 items running an exact match. In this case I want to perform a kind of like query that finds “565%” entries. Eventually I need to run this in one query.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:52:55+00:00Added an answer on May 27, 2026 at 6:52 am

    Something like this might be what you want:

    SELECT …
    FROM atable
    WHERE zip = @zip
    
    UNION ALL
    
    SELECT …
    FROM atable
    WHERE NOT EXISTS (
      SELECT *
      FROM atable
      WHERE zip = @zip
    )
      AND zip LIKE CONCAT(LEFT(@zip, 3), '%')
    

    This may not be the most efficient solution, but at least it is a single query so might do well as a starting point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I want to get 3 documents which fit one of these attributes Class
Assuming I'm trying to automate the installation of something on windows and I want
We are redesigning table schema in postgres. It used to have a linker table
Assuming the URL is http://localhost:8080/project-name/resource.xhtml , I want to obtain the following http://localhost:8080/project-name in
Assuming this table with nearly 5 000 000 rows CREATE TABLE `author2book` ( `author_id`
Assuming I have a table with one field called ID that stores 100 different
Assuming I have a collection in MongoDB with 5000 records, each containing something similar
Assuming one table CAR with two columns CAR_ID (int) and VERSION (int) . I
Every time is set up a new SQL table or add a new varchar
Assuming i got 3 data:i=01,j=02,k=03 and i want to set these 3 data indiviually

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.