I'm not sure if get the issue. But from what I know, SQLLite has internal row numbers. Those are not used in a query by a developer.
Wrong. They are used everytime a Table has an Integer-column with Attribute Primary Key, since that column actually becomes an Alias for "rowid"
Note: This only applies to tables NOT created with "without rowid"-modifier (or whatever it's called)
Tables created with "without rowid"-modifier of course don't have that, but such tables are 1 in a billion
I can create tables without an ID-PrimaryKey (Integer), and still use "rowid" in my queries.
There is only one caveat: You can't use "rowid" as a "link" to a Foreign Key
As developer you would have one ID field, with unique integer ID's (autoincrement) and you use that in SQL.
Don't use Autoincrement in SQLite. Period!
I'm allmost sure that "With" is not a valid SQL statement. You first "Select" will return all fields where you would want Row_Num only.
I would allmost say: 'Select ID from CTE where ID = ' + inttostr(aId); will at least run without errors.
Open your database table in a SQLite database tool and see for yourself: data is stored with a unique identifier, in a primary key field.
Utter Nonsense.
CTE's ("With") are supported pretty much across all modern Database-Engines.
I use SQL's with "WITH"-Statements (CTE's) every day, and yes, even in SQLite (which is only my test Database)
at TS
you were close...
untested, though
Q1.SQL.Text := 'WITH CTE as (SELECT *, ROW_NUMBER() OVER(ORDER BY '+QOrder+') as Row_Num From Game INNER JOIN ' +
'Player ON ID = IDNo where ' + QWhere +') Select ID,Row_Num FROM CTE WHERE ID="' + aID + '";';
EDIT:
A word of advice:
1) Don't use "SELECT * FROM, especially not on joined tables
2) use aliases on your tables, or at least fully qualify your columns to which table they belong
the line with "... ON ID=IDno.." i would always ask myself "is ID in Game or in Player?"
Q1.SQL.Text := 'WITH CTE as
(SELECT G.ID, ROW_NUMBER() OVER(ORDER BY '+QOrder+') as Row_Num From Game AS G '+
'INNER JOIN Player AS P ON G.ID = P.IDNo where ' + QWhere +
') Select ID,Row_Num FROM CTE WHERE ID="' + aID + '";';
And is ID really a Text/String?? Note the doublequotes at the end
EDIT2: Of Course, in case of aliasing QOrder and QWhere MUST contain the correct aliases!
e.g.
QOrder:='P.PlayerName'
QWhere:='P.IDno=42'
and similar