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

The Archive Base Latest Questions

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

Table subject : +——–+—-+ | name | id | +——–|—-+ | apple | 3

  • 0

Table subject:

+--------+----+
|  name  | id |
+--------|----+
| apple  | 3  |
| banana | 1  |
| tree   | 4  |
| horse  | 6  |
| bird   | 7  |
| raq    | 2  |
+--------+----+

So I try to have an ouput like that (if, for example, my $id_subject = 4, my next row MUST be 5 -6 7-1….)

+--------+----+
|  name  | id |
+--------+----+
| tree   | 4  |
| horse  | 6  |
| bird   | 7  |
| banana | 1  |
| raq    | 2  |
| apple  | 3  |
+--------+----+

My query:

select subject_url,subjects.id
    from students_group
    left join teacher_group on teacher_group.group_school_id = students_group.group_id
    left join subjects on teacher_group.subject_id = subjects.id
    where   students_group.user_id = 83
    ORDER BY subjects.id = 5 desc

But I got this output:

+--------+----+
|  name  | id |
+--------+----+
| tree   | 4  |
| apple  | 3  |
| banana | 1  |
| horse  | 6  |
| bird   | 7  |
| raq    | 2  |
+--------+----+

How can I make it work as expected?

  • 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-27T00:27:57+00:00Added an answer on May 27, 2026 at 12:27 am
    ORDER BY 
    if (subjects.id=$id_subject, -1,
      if (subjects.id>$id_subject, 0, 1)
    ), subjects.id 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a table like this: yr subject 1960 Physics 1960 Chemistry 1961
I have the following table Name Subject Month Year ----- ----------- ----- ---- Raju
I have got table as given below in database: Name Grade Subject Ami HD
I have in my table this value ART(\'O\') in the field Subject. How do
I have a table say : id| AccID | Subject | Date 1 |
I have a cross reference table that looks like this: id document_id subject_id 1
I have a conversation table, and a user conversation table. CONVERSATION Id, Subject, Type
I am using hibernate 3 , oracle 10g. I have a table: subject. The
I have following two tables Table name: thread pk-> thread_id | thread_title | description
I have a table called Survey with a Group Column and a Subject Column

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.