I need to make a sql query were in I have a table which consists below columns
id Name Color
1 Water red
5 Sun blue Light
7 Fire green
10 Wter red
21 Son blue Light
24 Fore green
So the requirement is I have a record say
5 Sun blue Light
Now I need to get the index of above record from the sorted result of the Name. Say below can be the select query.
SELECT * FROM MYTABLENAME WHERE COLOR LIKE “blue/%” ORDER BY Name ASC
Note:- I cannot load all the records in my memory and iterate as the records can be huge at times. So need to come up with a query that gives the exact indexof the record without loading the records.
Thanks In advance
If you haven't stored the sort result in a temporary table, the only way to do this is to count how many records would be sorted before this record:
SELECT COUNT(*)
FROM MYTABLENAME
WHERE COLOR LIKE “blue/%”
AND Name <= 'Sun'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.