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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:56:15+00:00 2026-05-27T17:56:15+00:00

Say i have a table Guest and it has column g_id : values 1

  • 0

Say i have a table Guest and it has column g_id : values 1 to 10.

Now i want the query to return me the g_id’s neither in ascending order nor in descending..
but i want the 4th then 3rd and then 5th entry, in this particular order.
Also i want just the 4th 3rd and 5th entry.

say my entries have an id and a name . ;i.e. my table Guest has these two tables.
Now my table is as following.

1 A
2 B
3 C
4 D
5 E
6 F
7 G
8 H
9 I
10 J

Now i want just the entry with 4th 3rd and 5th g_id, and in this particular order.

How do i write the SQL query?
Thanks.

Select * from Guest ___________???

Kindly fill in the gaps.

  • 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-27T17:56:15+00:00Added an answer on May 27, 2026 at 5:56 pm

    You can use a CASE statement in your ORDER BY to use a fake column to sort on and a WHERE IN clause to only return the values you need.

    SELECT * 
    FROM   Guest
    WHERE  g_id IN (3, 4, 5)
    ORDER BY
           CASE WHEN g_id = 4 THEN 1
                WHEN g_id = 3 THEN 2
                WHEN g_id = 5 THEN 3
           END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem. My table, say tab1, has name column as follows
Say I have a table called myTable. What is the SQL command to return
Lets say I have one table called REVIEWS This table has Reviews that customers
I have a pretty large table (20M records) which has a 3 column index
I have a table with a column that I want to extract out and
Let's say I have a data.table and I want to select all the rows
Say I have a table called xml that stores XML files in a single
Say I have this table: Person table -------------- PersonId Address table ------------ AddressId PersonAddressId
Say I have this table schema. ID AccNo Amount Say I have this data
Say I have a table called HoursCharged ChrgNum(varchar(10)) CategoryID(uniqueidentifier) Month(datetime) Hours(int) CategoryID is a

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.