I have a table for news and I want to select the 3 newest things in each row, they're numbered 1 as the oldest and each data I add it will be a number higher. So how do you get the three newest things and display the them in places? (Sorry I can't think of how to phrase my question)
EDIT: I don't have like html or anything so show the desired effect, but I can explain it. I have an SQL Table that has 4 rows. ID, TITLE, DATE, and POST. This is a news feed, and I want to display the 3 newest news "articles" on the homepage. But I don't want to just display them as lists, I want to put the title in a top div, next to the date, I want to order it by the primary key (ID) and then have the post in a div under the title and date. Here's an attempt to show you:
Title | Date Newest news. Etc. Insert Big Paragraph of news here etc etc. Title | Date 2nd Newest news. Etc. Insert Big Paragraph of news here etc etc. Title | Date 3rd Newest news. Etc. Insert Big Paragraph of news here etc etc.
If I am getting you correctly you can use
LIMIT
andORDER BY
Example
If my understanding of your question is correct, it seems you have a table with a row identifier (numbered 1 to ... n) and you want to run a query that will bring back the 3 most recent inserted records ?
If so:
Lets assume you have a table called Books with the below structure:
What you need to do is run the following SQL:
I hope this helps :)
first, please dont use 'date' as your field name, lets say you rename it as news_date. How about this?