How to show result from first 5 or 10 records in a table based on a condition from mysql database

    To show result from first 5 or 10 records on the basis of some condtion from mysql database use following query:
    SELECT id FROM
    (SELECT id, status FROM data
    ORDER BY created_at DESC
    LIMIT 0, 5)  AS t WHERE t.status = 'failed'

    Where data is table name and status is field name contains status "failed" or "success" if there are 5 consecutive it will display 5 records otherwise failed-success in last 5 records

    Note: You can change the limit from 5 to 10, 20 etc depends upon your requirement
    5
    Average: 5 (1 vote)