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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:24:19+00:00 2026-06-13T12:24:19+00:00

SELECT p.* FROM Products p LEFT JOIN offertran ot ON p.prod_id = ot.prod_id LEFT

  • 0
SELECT p.*
FROM Products p
LEFT JOIN offertran ot 
ON p.prod_id = ot.prod_id

LEFT JOIN Offers o
       ON ot.offer_id = o.id
      AND o.dF<=3 
      AND o.dt>=3

ORDER BY o.id DESC, 
          p.prod_id ASC
LIMIT 20

Please check the output in fiddle

I want the existing condition as it is and some more added conditions as listed below:

  1. In this output, I got Offered products are shown first (This is important, after this)
  2. I want New products – that is sort based on todaysDate - p.pdate less than 30 days
  3. Then show the products those have p.pre != ''
  4. Then show them who dont have price ie. p.price ==0
  5. Then arrange other products by prod_id DESC

I want all in one, to add those 5 points in this existing query

I hope you got the problem. I need an immediate response.
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-13T12:24:20+00:00Added an answer on June 13, 2026 at 12:24 pm

    Give this a go:

    SELECT p.*, o.id
    FROM Products p
    LEFT JOIN offertran ot 
    ON p.prod_id = ot.prod_id
    LEFT JOIN Offers o
           ON ot.offer_id = o.id
          AND o.dF<=3 
          AND o.dt>=3
    ORDER BY o.id DESC, 
    case when p.pDate > curdate()-interval 30 day then p.pDate else '1970-01-01' end desc,
    case when p.pre != '' then 1 else 0 end desc,
    p.price asc,p.prod_id DESC
    LIMIT 20;
    

    I am a little unclear what you mean in point 2:

    Do you want the resulting dates sorted DESC or ASC? What happens to those rows with a date older than 30 days? Exclude? Drop into the next sorting level?

    I’ve taken a guess at what you meant. I am sure you can play around with the query if I have misunderstood.

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

Sidebar

Related Questions

Check this fiddle for DB and tables SELECT p.* FROM Products p LEFT JOIN
Any idea why query SELECT m.* FROM products_description pd, products p left join manufacturers
$query = SELECT sum(o.feeship) feeship_total, (SELECT SUM(p.products_price) FROM products p left join orders_products op
I have the following query: select * from products as p left join files
SELECT products.* FROM products LEFT JOIN product_category ON products.id_product = product_category.id_produs LEFT JOIN categories
If I use this statement: $query = select * from Products where category_description='.$search_dept.' ORDER
I've got a MySQL query somewhat like the following: SELECT * FROM products LEFT
I have the below query: SELECT p.id as prod_id, * FROM products AS p
select distinct p.product_id from cscart_products p left join product_bikes pb on p.product_id = pb.product_id
I have this query SELECT products_list.id_cat_unique, products_categories_list.*, COUNT(products_list.id_cat_unique) as counter FROM products_categories_ids LEFT JOIN

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.