Skip to content
Advertisement

How to fetch the the second row

I have a query below which is used to make a view. This query pulls the latest record of the report_id.

One report_id can have multiple unique report_info_id

This results in data something like

Lets take the example of last record where report_id= 130

Now it is required that in first query I want such data if the status is “Edited after validation” then pull the second row of that report_id

Expected result

Advertisement

Answer

Based on your description of the problem you need not the second row in each group as such, but a row that satisfies an additional criteria. You want to skip the row with status “Edited after validation”. To do that you can simply add a WHERE filter to your query:

or

Both queries produce the same result if status can be only either Edited after validation or Validated. If status can have some other values as well, pick the variant that suits the necessary logic.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement