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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:22:06+00:00 2026-05-14T05:22:06+00:00

My query string is like: SELECT … FROM maintable LEFT JOIN table1 on (maintable.id

  • 0

My query string is like:

SELECT ... FROM maintable
LEFT JOIN table1 on (maintable.id = table1.idx)
LEFT JOIN table2 on (table1.idy = table2.idy)
LEFT JOIN table3 on (table2.idz = table3.idz)
WHERE (condition1 OR condition2 OR condition3)
AND maintable.status = static

//condition1 & condition2 & condition3 are kind of
table3.idz = 101, table3.idz = 3, maintable.id IN (1,2,3,4), and so on

For the results I want entries that meet condition1 to be returned first, then entries that meet condition2, and finally entries that meet condition3. Any ideas?

  • 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-14T05:22:06+00:00Added an answer on May 14, 2026 at 5:22 am

    To get the sorting in the order you want, use your conditions in the ORDER BY, but use DESC after them.

    SELECT *
    FROM person
    WHERE (condition1 OR condition2 OR condition3)
    AND maintable.status = static
    ORDER BY
        condition1 DESC,
        condition2 DESC,
        condition3 DESC
    

    If this doesn’t work because your query is more complex, then you can use boolean logic to change your query (A OR B OR C) AND D into (A AND D) OR (B AND D) OR (C AND D) then you can use the following query:

    SELECT *
    FROM person
    WHERE (condition1 OR condition2 OR condition3)
    AND maintable.status = static
    ORDER BY
        condition1 AND static DESC,
        condition2 AND static DESC,
        condition3 AND static DESC
    

    The AND static is not necessary here because all rows return it, but in a more complex example (where you also return some rows which are not static) then you would have to do it in this way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this part of code string query = SELECT ID, COL1 FROM TABLE1
My current query (doesn't work) SELECT url FROM table WHERE 'http://www.longurl.com/some/string' like '%' .
I want to replace a query string like this: SELECT abc,def,ghi,jhk FROM table.... with
My query is: result = connection.execute( select id_number from Table where string like '_stringStart%'
I am building an ObjectQuery like this: string query = select value obj from
I'm trying to run a query through the ORM like this: SELECT * from
I want to create a database query string which should be like this, (SELECT
My sql string is like: SELECT t.* FROM table AS t GROUP BY t.month
In SQL Server 2000 I have a query like SELECT DISTINCT A.COLUMN1, B.COLUMN2 FROM
Assuming a generic query like: SELECT * FROM items ORDER BY type ASC, created

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.