Hi I would like to have added line number to result set with the number specifying the order in result set. Eg: I have competitors men and women and I would like to know what was the order of Jane Doe in the competition among women.
So I cannot get the order of Jane Doe without getting the whole result set and I have to construct foreach and go one record by one in PHP?
SQL has something like this:
SELECT competitor.finish_time, competitor.name, number = ROW_NUMBER() OVER (ORDER BY competitor.finish_time)
@tykus_ikus It is nice but it is still iteration over result set - I would like to have something to ask DB directly - if it is possible - simply how to ask: What was the order of Jane Doe among women?
If you are just hitting a single competitor in the query then your solution will be database-specific - as you say SQL has a ROW_NUMBER() function, but this is not available in MySQL (is this your DB of choice here?)
A DB::select type query is necessary in this case - there are a number of articles like this which show you how to emulate the ROW_NUMBER() functionality in MySQL