Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - QDB - how to retrieve row number of result row!: (7 Items)
   
QDB - how to retrieve row number of result row!  
Hi all,

i am looking for an option to get the row number of a select or sub-selects. I found at the SQLite homepage, that "ROWID
", "OID", or "_ROWID_" exists, but it doesn't work for QDB. 

Thanks a lot,

Florian
Re: QDB - how to retrieve row number of result row!  
Hi Florian,

ROWID should work the same for QDB since it is just being passed back as part of the result as a column.   I think ROWID
 is not the rowid of a result however, I think it is used as the primary key of the table.

Dan



On 2010-02-04, at 10:30 AM, Florian Becher wrote:

> Hi all,
> 
> i am looking for an option to get the row number of a select or sub-selects. I found at the SQLite homepage, that "
ROWID", "OID", or "_ROWID_" exists, but it doesn't work for QDB.
> 
> Thanks a lot,
> 
> Florian
> 
> 
> 
> _______________________________________________
> 
> Development
> http://community.qnx.com/sf/go/post46546
> 
> 

Dan Cardamore
dcardamore@qnx.com



Re: QDB - how to retrieve row number of result row!  
Hi Dan,

thanks for your answer. Is there any chance to get this id, which is shown at a SELECT at the beginning of a row (0001,
0002,...)?

The background is, i SELECT over 3 tables and UNION them. Now i need an identifier which is increasing over all three 
SELECT statements, to be able to SELECT exactly one result of those 3 UNION SELECTS. Is there a way, to perform such a 
operation?

Thanks in advance for your help,

Florian
Re: QDB - how to retrieve row number of result row!  
> thanks for your answer. Is there any chance to get this id, which is shown at 
> a SELECT at the beginning of a row (0001,0002,...)?
> 
> The background is, i SELECT over 3 tables and UNION them. Now i need an 
> identifier which is increasing over all three SELECT statements, to be able to
>  SELECT exactly one result of those 3 UNION SELECTS. Is there a way, to 
> perform such a operation?

Hi Florian,

Say I wanted the 10th to 15th results from a union of other results. What I would try is:
select id from (select ... union ... select ... etc) LIMIT 5 OFFSET 10;

(fetch 5 results starting at offset 10)

I'm not sure I fully understand what you need to accomplish, I hope this helps.


Regards,
Gilles
Re: QDB - how to retrieve row number of result row!  
It sounds like you're just looking for the loop counter that qdbc prints when looping through the result rows.  It's not
 a number that's stored in the database, or in the result.

The code (in services/qdb/lib/qdb.c:qdb_printmsg()) is:
496			for (row = 0; row < nrows; ++row) {
497				fprintf(fp, "%05d:\t", row);

You cannot use that specific number to refer to a row in a table; you can use it to refer to an offset in a query (with 
something like the OFFSET keyword as Gilles mentioned), but that might not be what you want.  (For example, if rows are 
added/changed/deleted that would modify your result set the offset into that result will change.)
Re: QDB - how to retrieve row number of result row!  
I think a better location to get this answer would be the sqlite.org forums.   I think what you're looking for can't be 
done with sqlite the way it is now.

Dan


On 2010-02-05, at 2:35 AM, Florian Becher wrote:

> Hi Dan,
> 
> thanks for your answer. Is there any chance to get this id, which is shown at a SELECT at the beginning of a row (0001
,0002,...)?
> 
> The background is, i SELECT over 3 tables and UNION them. Now i need an identifier which is increasing over all three 
SELECT statements, to be able to SELECT exactly one result of those 3 UNION SELECTS. Is there a way, to perform such a 
operation?
> 
> Thanks in advance for your help,
> 
> Florian
> 
> 
> 
> _______________________________________________
> 
> Development
> http://community.qnx.com/sf/go/post46621
> 
> 

Dan Cardamore
dcardamore@qnx.com



Re: QDB - how to retrieve row number of result row!  
Hi all,

thank you very much for your answers. I created a new table without specifying a primary key, which results in the 
behavior to retrieve the database ROWID when i select the ROWID. Furthermore i created a unique index on one column to 
prevent adding the same id twice to the table.

Cheers,
Florian