0

I'm having a table Content with following structure,

Id | title | category | content | created_at

At least it's contained more than one category and lot of article for each category.

I want to display the three last article of each category on my index page. How can I do that using a single SQL query ?

MJoy
  • 1,349
  • 2
  • 9
  • 23

1 Answers1

0

You can select data with limit of 3 and in descending order.so it will gives you the last three record.Here i have already assume that you have another table rather than Content table named Article which have all the data of article along with Content table id as foreign key reference.

select 
    * 
    from 
    `article` where `category_id`='$category_id'
    order by 
     id desc
    limit 3
CodeBreaker
  • 395
  • 2
  • 9