Select last two rows from mysql php

Mrigank

I have a database like this:

+----------+----------+------+
| username | password | time |
+----------+----------+------+
| a        | b        | 1234 |
| c        | d        | 5678 |
| e        | f        | 9012 |
+----------+----------+------+

Now I have to arrange this by time so I ran:

mysql_query("SELECT * FROM `table` ORDER BY `time`")

This showed me rows arranged by time in ascending order, but I have to get only username c and e or I have to get the last two rows from the query.

I have tried:

mysql_query('SELECT * FROM `table` ORDER BY `time` LIMIT 2')

But this showed me usernames a and c but I have to get the last two, how to do that?

Nathan
SELECT * FROM table
ORDER BY time DESC
LIMIT 2

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

mysql - select last two rows in query

From Dev

Select last N rows from MySQL - codeigniter

From Dev

Select last N rows from MySQL - codeigniter

From Dev

Select the last date from multiple rows in mysql

From Dev

PHP MySQL select two random rows but not with rand()

From Dev

PHP and MySql - fetching rows from two tables

From Dev

Select rows from two different tables but order by date using php and MySQL

From Dev

MySQL: select last (max) value from column and count of all rows

From Dev

How to select non-matching rows from two mysql table

From Dev

MySQL select row with two matching joined rows from another table

From Dev

Mysql statement to select distinct rows from two columns

From Dev

Mysql statement to select distinct rows from two columns

From Dev

mysql select from table where two (or more) rows match,

From Dev

Mysql Select Two Rows in One

From Dev

Select last rows in MySQL and stop on matching condition

From Dev

PHP Select from MySQL table and return column with most rows

From Dev

how to select alternate rows from mysql using php

From Dev

MySQL PHP insert data from two rows into multidimensional array

From Dev

MySQL select all rows from this year to a specific month from last year

From Dev

How to select rows in MySQL/PHP?

From Dev

PHP MySQL select rows where date time value within the last n minutes

From Dev

Doctrine - select last 4 rows from table

From Dev

Doctrine - select last 4 rows from table

From Dev

Select all rows from last inserted

From Dev

MySQL select the last two inserted IDs

From Dev

MySQL concurrent select from rows

From Dev

Select multiple rows from MySQL

From Dev

Query syntax with php variables to select from two MySQL tables

From Dev

mysql select rows based on two columns

Related Related

  1. 1

    mysql - select last two rows in query

  2. 2

    Select last N rows from MySQL - codeigniter

  3. 3

    Select last N rows from MySQL - codeigniter

  4. 4

    Select the last date from multiple rows in mysql

  5. 5

    PHP MySQL select two random rows but not with rand()

  6. 6

    PHP and MySql - fetching rows from two tables

  7. 7

    Select rows from two different tables but order by date using php and MySQL

  8. 8

    MySQL: select last (max) value from column and count of all rows

  9. 9

    How to select non-matching rows from two mysql table

  10. 10

    MySQL select row with two matching joined rows from another table

  11. 11

    Mysql statement to select distinct rows from two columns

  12. 12

    Mysql statement to select distinct rows from two columns

  13. 13

    mysql select from table where two (or more) rows match,

  14. 14

    Mysql Select Two Rows in One

  15. 15

    Select last rows in MySQL and stop on matching condition

  16. 16

    PHP Select from MySQL table and return column with most rows

  17. 17

    how to select alternate rows from mysql using php

  18. 18

    MySQL PHP insert data from two rows into multidimensional array

  19. 19

    MySQL select all rows from this year to a specific month from last year

  20. 20

    How to select rows in MySQL/PHP?

  21. 21

    PHP MySQL select rows where date time value within the last n minutes

  22. 22

    Doctrine - select last 4 rows from table

  23. 23

    Doctrine - select last 4 rows from table

  24. 24

    Select all rows from last inserted

  25. 25

    MySQL select the last two inserted IDs

  26. 26

    MySQL concurrent select from rows

  27. 27

    Select multiple rows from MySQL

  28. 28

    Query syntax with php variables to select from two MySQL tables

  29. 29

    mysql select rows based on two columns

HotTag

Archive