Nov 22, 2009

[mysql]how Can I Get The Newest Record?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Databases

[mysql]how Can I Get The Newest Record?

jedipi
I am currently developing a website which need to show the newest record in index page.
The newest record should retrieve from mysql database.

now, the question is....
how can i get the newest inserted record from a particular table in myssql database???

Comment/Reply (w/o sign-up)

signatureimage
Dear jedipi,


While deciding on the columns (=fields) of your data-base table,
you should definitively use an extra column that has the
data-base attribute autoincrement .

This extra column will be used by the data-base engine as a counter,
and the value of this column will be created by the data-base engine,
everytime that a new row is inserted into the data-base table.

Its value will auto-increment - as the name suggests.

Most data-base designers use the name id for this extra column.

If you want to obtain the last inserted row of the data-base table,
all you have to to is request the row that has the highest value in that column.

You ask the highest value with the MAX() data-base function, as in
SQL
SELECT MAX(id) FROM myuserid_mydatabasetable;

Comment/Reply (w/o sign-up)

jedipi
QUOTE (signatureimage @ May 23 2005, 01:35 AM)
Dear jedipi,
While deciding on the columns (=fields) of your data-base table,
you should definitively use an extra column that has the
data-base attribute autoincrement .

This extra column will be used by the data-base engine as a counter,
and the value of this column will be created by the data-base engine,
everytime that a new row is inserted into the data-base table.

Its value will auto-increment - as the name suggests.

Most data-base designers use the name id for this extra column.

If you want to obtain the last inserted row of the data-base table,
all you have to to is request the row that has the highest value in that column.

You ask the highest value with the MAX() data-base function, as in
SQL
SELECT MAX(id) FROM myuserid_mydatabasetable;

*

Thanks signatureimage,
yea, autoincrement is a good way to do that...
I have used this method for the new tables in the database.

However, the system I am developping is going to be integrated with the old system. There are some tables in the database already.
Can i add extra autoincrement column to the old table without affecting the old system???

 

 

 


Comment/Reply (w/o sign-up)

signatureimage
Dear jedipi,

Yes, you can add a new column to an existing data-base table.

First method: with the interactive phpMySql dialogs that you have on your control panel of asatahost.com

Second method: with the SQL statement:
SQL
ALTER TABLE ...


May I suggest that you visit the mySQL website for the full explanation of this method.

There, you will also find examples of how to let the data-base engine automatically generate the missing autoincrement values.

The mySQL website is not the only source of valuable information, you should also visit SQL org.
There you can find more general information and tutorials.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Mysqlhow Newest


    Looking for mysql, newest, record

See Also,

*SIMILAR VIDEOS*
Searching Video's for mysql, newest, record
advertisement



[mysql]how Can I Get The Newest Record?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com