[sqlite] Getting row number in a sorted list.

2015-08-20 Thread R.Smith
On 2015-08-20 07:44 AM, Anthrathodiyil, Sabeel (S.) wrote: > Hi, > I think there is ambiguity in the example I provided, I wouldn't need a > ranking in my case as I need the offset (think row number is misleading) of > the first record in the sorted list. > > Here is my use case. > Find the ro

[sqlite] Getting row number in a sorted list.

2015-08-20 Thread Anthrathodiyil, Sabeel (S.)
John McKown Sent: Wednesday, August 19, 2015 6:32 PM To: General Discussion of SQLite Database Subject: Re: [sqlite] Getting row number in a sorted list. On Wed, Aug 19, 2015 at 7:40 AM, Simon Slavin wrote: > > On 19 Aug 2015, at 1:16pm, Anthrathodiyil, Sabeel (S.) < > santhrat a

[sqlite] Getting row number in a sorted list.

2015-08-19 Thread R.Smith
> > SELECT count(sub.Name) + 1 AS Rank, a.Name > FROM NameTable AS a LEFT OUTER JOIN NameTable AS sub ON sub.Name < > a.Name > WHERE a.Name LIKE 'P%' > GROUP BY a.Name > ORDER BY a.Name > LIMIT 1 > > > -- Rank | Name > -- | -- > -- 4 | PQRS I shou

[sqlite] Getting row number in a sorted list.

2015-08-19 Thread R.Smith
On 2015-08-19 03:02 PM, John McKown wrote: > On Wed, Aug 19, 2015 at 7:40 AM, Simon Slavin wrote: > >> 1|ABCD >> 2|CDE >> 4|AXN >> 5|AXN2 >> 6|PQRS2 >> sqlite> select rowid from NameTable where Name between 'P' and 'PZZZ' >> limit 1; >> 6 >> >> >> Hum, that probably isn't what the OP wanted.

[sqlite] Getting row number in a sorted list.

2015-08-19 Thread Simon Slavin
On 19 Aug 2015, at 2:00pm, R.Smith wrote: > Seriously though, if that column is not COLLATE NOCASE declared, 'PZZZ' will > fail. Either ensure your column has COLLATE NOCASE or perhaps simply choosing > the highest (non UTF-8) character such as: > > WHERE name BETWEEN 'P' AND 'P~' > >

[sqlite] Getting row number in a sorted list.

2015-08-19 Thread Clemens Ladisch
Simon Slavin wrote: > SELECT rowid FROM NameTable > WHERE name BETWEEN 'P' AND 'P' > > This will execute faster if you have an index on 'name' in NameTable. > > [Yes I know 'P' is lazy. Until you find someone with that name > (presumably Polish) with that name bite me.] If the colu

[sqlite] Getting row number in a sorted list.

2015-08-19 Thread R.Smith
On 2015-08-19 02:40 PM, Simon Slavin wrote: > > SELECT rowid FROM NameTable > WHERE name BETWEEN 'P' AND 'P' > ORDER BY name > LIMIT 1 > > This will execute faster if you have an index on 'name' in NameTable. > > [Yes I know 'P' is lazy. Until you find someone with that

[sqlite] Getting row number in a sorted list.

2015-08-19 Thread Simon Slavin
On 19 Aug 2015, at 1:16pm, Anthrathodiyil, Sabeel (S.) wrote: > Example, for below entries in NameTable > > Name > > 1. PTN > > 2. ABCD > > 3. CDE > > 4. PQRS > > 5. AXN > > > I want to get the row number of the first name that starts with 'P' in the > sort

[sqlite] Getting row number in a sorted list.

2015-08-19 Thread Anthrathodiyil, Sabeel (S.)
Hi, I have a database with NameTable having name records in it, I need to get the row number of the first record in the sorted list of names for which the search name matches. Example, for below entries in NameTable Name 1. PTN 2. ABCD 3. CDE 4. PQRS 5. AXN

[sqlite] Getting row number in a sorted list.

2015-08-19 Thread John McKown
On Wed, Aug 19, 2015 at 7:40 AM, Simon Slavin wrote: > > On 19 Aug 2015, at 1:16pm, Anthrathodiyil, Sabeel (S.) < > santhrat at visteon.com> wrote: > > > Example, for below entries in NameTable > > > > Name > > > > 1. > ?? > PTN > > > > 2. ABCD > > > > 3. CDE > > > > 4. PQRS >