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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:41:20+00:00 2026-06-11T16:41:20+00:00

Possible Duplicate: Database query to search using address I am developing a search functionality

  • 0

Possible Duplicate:
Database query to search using address

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

  • when user search by zip code, matched results should be displayed in descending order
  • when user search by name matched results should be display alphabetically 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 Ii want ORDER BY for every condition. for example ‘xyz’ matches to the firstname I want to sort the result in ascending order.

How can i do that? Any suggestions will be greatly appriciated

  • 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-11T16:41:21+00:00Added an answer on June 11, 2026 at 4:41 pm

    Try this:

    SELECT 
      city, postcode, name 
    FROM 
      dealers
    WHERE 
    ...
    ORDER BY
      CASE WHEN @postcodeParam IS NOT NULL THEN postcode END DESC,
      CASE WHEN @nameParam     IS NOT NULL THEN name     END, 
      CASE WHEN @citynameParam IS NOT NULL THEN cityname END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Query Microsoft Access MDB Database using LINQ and C# Im working with
Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
Is it possible to duplicate a MySQL database from their files? [I know mysqldump
Possible Duplicate: SQL Query with MySQL I implement a Rest Web Service (JAX-RS) using
Possible Duplicate: The query results cannot be enumerated more than once? I am using
Possible Duplicate: Problem with database in CodeIgniter Alright, I've googled this the last two
Possible Duplicate: Fetch data in database table insert it if not exist else return
Possible Duplicate: How can WCF consuming data from database phpmyadmin? I want to ask
Possible Duplicate: How to empty DB in heroku I have a Postgres database on
Possible Duplicate: How to get random record from MS Access database In my project

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.