0
votes

I have 3 Tables:

Tables

So I need an SQLite query that shows me the Row Number of the s_id=7 ( it must be here 3 )

I search too much on the Internet to find tips but I didn't find! it will be perfect if someone can help me with that.

1
Please read the tag info for the tag you used and provde an MRE as described there. stackoverflow.com/tags/sqlite/info Also describe what you tried and how exactly it failed. Describing what you want is not considered a question here.Yunnosch
The row number may not be 3 tomorrow. If you need an id other than 7, that field needs to be included in the Section table.Gilbert Le Blanc
What is the logic that generates 3 for s_id` 7? Please explain what you are trying to do.GMB
I want to know the row number of the value s_id= 7, so if you look to the Section Table you will see that the s_id=7 is the 3ed row! It doesn't matter if tomorrow can be 2 or 1 I want to get the actual row number of the value that's itSelin Dönmez

1 Answers

0
votes

You can use window functions like this:

select *
from (
    select s_id, row_number() over(order by s_id) as rn
    from section
) s
where s_id = 7

Or, if your version of SQLite does not support window functions, you can use a subquery:

select s_id,
    (select count(*) from section s1 where s1.s_id <= s.id) as rn
from section s
where s_id = 7