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 8618235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:03:33+00:00 2026-06-12T06:03:33+00:00

I am developing a search functionality to search for dealers by their address(i.e. by

  • 0

I am developing a search functionality to search for dealers by their address(i.e. by postcode(zip) or by name or by city)for my project. user will be provided with only one html input field to enter the search term (users can enter only one search term at a time, i.e. either zip code or name or city (combinations are not allowed)). The conditions to develop a query are as below

  1. When user search by zip code, matched results should be displayed in descending order
  2. When user search by name matched results should be display alphabetically
  3. Same as city name

Some times there is a possibility that name can also contains zip code in that case results should be shorted by zip code.

I tried like this

select city, postcode, name
  from dealers
  where name ='xyz' OR
        postcode ='xyz' OR
        city='XYZ'
  ORDER BY postcode desc

But I want ‘ORDER BY’ for every condition. for example ‘xyz’ matches to the first name I want to sort the result in ascending order. How can I do that?

  • 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-06-12T06:03:34+00:00Added an answer on June 12, 2026 at 6:03 am

    Life would be easier if all your terms were sorted in ascending order.

    I assume that your actual application is using a variable rather than a hard-coded string. So the solution should look something like this:

      select city, postcode, name
      from dealers
      where name = p_search_term OR
            postcode = p_search_term OR
            city = p_search_term
      ORDER BY case when postcode = p_search_term then p_search_term else 1 end desc
               , case when name = p_search_term then p_search_term else city end asc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a search engine for my web project (PHP/MySQL). User should be able
Possible Duplicate: Database query to search using address I am developing a search functionality
I am developing an App which has a search functionality for user's emails with
I am developing a search functionality with wicket. The DropDownChoice class is used to
I am developing a website in which i want to give a search functionality
I'm developing a search engine for a CCG. I want the user to be
I am developing an android app which requires search functionality. My app contains action
I'm developing a Ruby on Rails application need some advanced search engine functionality: specifically,
I'm developing a search form with a button that adds up to 4 State/City
I'm currently developing a search, where users need to search people by their first

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.