php show top 3 records from mysql

Hewlett-packard Hewlett packard lithium...
October 6, 2010 at 10:44:36
Specs: Windows XP, 4/8
hope someone can help.
Have a table
just want to show data from a mysql database

table name = transactions
column name = city

show city column data for last 3 records added.

so something like
SELECT TOP3('cities') from transactions

See More: php show top 3 records from mysql

Report •

Report •

October 10, 2010 at 19:34:19
A relational database has no concept of "last N records entered", unless you have a field containing a sequence number or timestamp. There are no promises as to what order records will be retrieved in, unless you specify an ORDER BY sequence number or timestamp field. To limit to a given number of records, different SQL implementations use different keywords. Some use TOP and others use LIMIT (MySQL uses LIMIT). Your query might therefore be something like

SELECT city FROM transactions ORDER BY sequence_number DESC LIMIT 3;

Report •
Related Solutions

Ask Question