Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have two tables: product & offers.

products has (prod_id, category_id, prod_name, brand, price, status)
offers has (offer_id, prod_id, offer_type, discount_amt, validity)


I want to display products on a page, 20 products at a time.

The problem that I want to display all the products from the offers table arranged by descending offer_id and then display products from the products table except those in the offers table within that 20 limit.

How can I achieve that?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Seems pretty straightforward.

SELECT * from products left join offers on prod_id=prod_id
ORDER BY offer_id DESC LIMIT 20;

See it here: http://sqlfiddle.com/#!2/dff49/3/0

share|improve this answer
    
thanks for your help ers81239.. I solved my problem –  Anusha Sep 18 '12 at 8:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.