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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:08:38+00:00 2026-06-08T00:08:38+00:00

I have this query: SELECT user.user_id, user.user_name, user.user_hash, suspension.suspension_expireson FROM user LEFT JOIN suspension

  • 0

I have this query:

SELECT user.user_id,
       user.user_name,
       user.user_hash,
       suspension.suspension_expireson
FROM   user
       LEFT JOIN suspension
              ON suspension.suspension_user = user.user_id
WHERE  user.user_name = "tester"
ORDER  BY suspension.suspension_expireson DESC
LIMIT  1; 

It orders the suspension_expireson so that the highest number (it’s unixtime, so the furthest in the future) comes up first, but I want NULL to be ranked higher than any number. So if there’s a row with the value NULL in suspension_expireson, I want that one.

How should I modify the query to do that?

Thanks in advance!

  • 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-08T00:08:39+00:00Added an answer on June 8, 2026 at 12:08 am

    Use a CASE statement in the ORDER BY to give a lower constant value to nulls 0 than other rows, which get a 1. The 0 sorts ahead of the 1, then the rest (1) are subordered by suspension_expireson DESC.

    SELECT
      user.user_id, 
      user.user_name, 
      user.user_hash, 
      suspension.suspension_expireson 
    FROM 
      user 
      LEFT JOIN suspension ON suspension.suspension_user = user.user_id 
    WHERE user.user_name = "Tester" 
    ORDER BY
      CASE WHEN suspension_expireson IS NULL THEN 0 ELSE 1 END,
      suspension.suspension_expireson DESC
    LIMIT 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query like this SELECT user_id FROM user WHERE user_id NOT IN
I have this working query: $q = $this->db->query('SELECT u.name FROM users u JOIN user_group
I have a search query as $sql=SELECT user_id,user_name,user_occupation FROM profile WHERE user_email LIKE '%peace%';
I have this query: SELECT * From checkfinale where AssociateID = 51 AND `CompletedDate`
I have this query: $this->set('grades', $this->Grade->Query( SELECT AVG(grade), sections.section_name FROM grades, sections WHERE sections.id
I have this query: SELECT id, name FROM users WHERE ((id = 1) OR
I have the following query: UPDATE lessonstatus INNER JOIN user ON lessonstatus.user_id = user.user_id
I have this query: select problem_comments.user_id , problem_comment_id , problem_id , first_name , count(problem_comment_id)
I have this query: SELECT a.id as alert_id,a.user_id,a.date,a.msg_title,a.message,a.alert_type,a.school_or_contact_id, u.id as user_id, u.full_name, c.id as
I have this query. SELECT notes.id,enter.name as 'enter_name',step.title as 'flow status',notes.user_name as user_created,notes.created,notes.rel_client_id,td_doc_nr.value_string as

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.