Im trying to pull the last 5 entered rows in a mysql table...
in MSSQL i can use the following query "Select top 5 * from employees;"
Whats the query that I can use for MYSQL?
-Jim
Ed prochak - 19 Aug 2003 18:22 GMT
> Im trying to pull the last 5 entered rows in a mysql table...
>
[quoted text clipped - 3 lines]
>
> -Jim
These Last/First X rows always bother me. Why? They show that many
folks still treat relational databases as if they were file systems.
One of the fundamental concepts in relational databases is:
there is NO ORDER to the set of data contained in a table.
IOW, there is no such concept as the last 5 rows of a table!
Check the SQL standard. There is not TOP keyword. No LAST or FIRST
either. No ROWNUM
-----
With that out of the way, lets get to your question. In order to
answer, we need to know what you mean by "the last 5 entered rows". Is
that alphabetical order? (first name or last name?) Is it by when the
employee started? (hire date? or application received date?) Or maybe
by age (birthdate)? By height?
Once you define what you need/mean you'll see how to write the query
easily.
I honestly hope this helps.
Ed
Dave Benjamin - 19 Aug 2003 20:11 GMT
> Im trying to pull the last 5 entered rows in a mysql table...
>
> in MSSQL i can use the following query "Select top 5 * from employees;"
>
> Whats the query that I can use for MYSQL?
SELECT * FROM EMPLOYEES LIMIT 5
(you probably want an ORDER BY in there...)
Dave