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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:36:23+00:00 2026-05-25T02:36:23+00:00

To simplify the problem down for the question, I have a listings table and

  • 0

To simplify the problem down for the question, I have a listings table and a listings_featured table. The main listings tables holds the main data for all listings but the listings_featured table holds data for only listings which are featured.

I want to display listings ordered by whether they are featured or not first, meaning the rows which have a match when doing a LEFT or RIGHT JOIN should come first. How would I go about doing this with just one query rather than two?

EDIT

Also, is it possible to add a WHERE condition to the query that only applies to the joined records? For example, out of the featured listings, I only want the ones which have the condition WHERE featured_end_date > now() – this should only apply to the joined records. This is because the duration for which a listing is featured will be different to the actual expiry date of the listing.

  • 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-25T02:36:24+00:00Added an answer on May 25, 2026 at 2:36 am
    SELECT l.*
    FROM listings l
        LEFT JOIN listings_featured lf ON lf.lid = l.lid
    WHERE lf.lid IS NULL OR lf.featured_end_date > now()
    ORDER BY lf.lid IS NULL
    

    lf.lid IS NULL is FALSE for all featured listings so while sorting they get put before other listings.

    EDIT

    Added WHERE condition

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

Sidebar

Related Questions

I have a table created in a migration (only to simplify the problem) that
I'll simplify the problem as much as possible: I have an oracle table: row_priority,
I'm having a rather silly problem. I'll simplify the situation: I have a table
I would like to simplify my main build scripts, and I'd like to have
I have a differential operator that acts on two functions. To simplify the problem
EDIT: I've completed rephrased the question as I've been able to simplify my problem
To simplify the problem, I have a graph that contains nodes and edges which
MYSQL Database: I have a table of data that I need to put into
I've created a sample project to simplify my problem. I have this simple handler:
so here is the problem that I have so far. I tried to simplify

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.