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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:49:59+00:00 2026-06-11T21:49:59+00:00

I want to show rows where region = ‘sample’ as first rows in result.

  • 0

I want to show rows where region = ‘sample’ as first rows in result. I mean priority must be higher than another rows and they must be at the top.

I use the SQL below for this result.

SELECT * FROM works Where region = 'sample' UNION Select * FROM works Where region <> 'sample'

Is there any optimal way to get result without UNION?

  • 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-11T21:50:01+00:00Added an answer on June 11, 2026 at 9:50 pm

    First of all Union will not guarantee order. Even if you do it like that, there are chances not to be in the right order. So you have to do it with an order by clause.

    Easy

    select * from work order by case when region='sample' then 0 else 1 end
    

    better if you have an index on region

    select *,0 as ordb from work where region = 'sample'
    union
    select *,1 as ordb from work where region <> 'sample'
    order by ordb
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider my table with ten rows and I want to show first three rows
I want to always show the first two rows, which i have done using
I want to show datagrid content (rows,columns) in XPS document.I have 20 columns. When
I want to show a listbox(Table) with nearly 20 Million rows. How can I
I have a table with many rows of data, and I want to show
I want to design a music player with ListBox has 2 rows to show
I have a grid that has multiple rows. I want to hide/show one of
Have a gridview control which will show X amount of rows. I want to
I want to show and hide rows of a table based on the value
I have seen some iPhone apps in which they show first section of rows

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.