this is my SQL table:
+----------------+----------------+-----------+------------------------+ | User_Name | Password | IP | Login_Time | +----------------+----------------+-----------+------------------------+ | rthrthrhrt | fjdjetje5e | 127.0.0.1 | 2011-09-24 18:02:06 | | Empty | Empty | 127.0.0.1 | 2011-09-24 18:10:01 | | Empty | Empty | 127.0.0.1 | 2011-09-24 18:04:00 | | rsyrt | rwytw4364 | 127.0.0.1 | 2011-09-24 18:08:59 | | eryrjrj5 | Empty | 127.0.0.1 | 2011-09-24 18:03:56 | | reutreuetry | reuretyre | 127.0.0.1 | 2011-09-24 18:06:53 | | Empty | rthrtrt | 127.0.0.1 | 2011-09-24 18:05:51 | | djdjgdjh | 66735 | 127.0.0.1 | 2011-09-24 18:09:49 | | fgjdgjdhg | Empty | 127.0.0.1 | 2011-09-24 18:07:46 | | Empty | Empty | 127.0.0.1 | 2011-09-24 18:11:43 | +----------------+----------------+-----------+------------------------+
I am developing a brute force addon with PHP and MySQL. I would like to select last 3 minutes' records.
for example (what i'd like to do?): time is now: 2011-09-26 9:45:00. i would like to select all records between 2011-09-26 9:45:00 and 2011-09-26 9:42:00.
SELECT * FROM ( SELECT * FROM yourTableName ORDER BY id DESC LIMIT 10 )Var1 ORDER BY id ASC; Let us now implement the above query. mysql> SELECT * FROM ( -> SELECT * FROM Last10RecordsDemo ORDER BY id DESC LIMIT 10 -> )Var1 -> -> ORDER BY id ASC; The following is the output that displays the last 10 records.
SELECT * FROM (select * from suppliers ORDER BY supplier_name DESC) suppliers2 WHERE rownum <= 3 ORDER BY rownum DESC; Notice that although you want the last 3 records sorted by supplier_name in ascending order, you actually sort the supplier_name in descending order in this solution.
1 Answer. ORDER BY id ASC; In the above query, we used subquery with the TOP clause that returns the table with the last 5 records sorted by ID in descending order. Again, we used to order by clause to sort the result-set of the subquery in ascending order by the ID column.
MySQL SELECT statement is used to retrieve rows from one or more tables. The statement can also include UNION statements and subqueries. SELECT statement is used to fetch rows or records from one or more tables.
Use this sql query:
select * from myTable where Login_time > date_sub(now(), interval 3 minute) ;
This query will work even if your table is not updated...
select * from myTable where Login_time > select max(time) - interval 3 minute ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With