1
select @pv:=categoryID as 'categoryID', name, parentID from categories
join
(select @pv:=4) tmp
where parentID = @pv

above query working on MYSQL but its not working on my android mobile SQLite database. Is there any other solution available ?enter image description here

CL.
  • 165,803
  • 15
  • 203
  • 239
Swapnil
  • 654
  • 7
  • 26

1 Answers1

4

Instead of some vendor-specific syntax, SQLite uses the common table expressions defined in the SQL standard for recursive queries:

WITH RECURSIVE subtree
AS (SELECT categoryID, name, parentID
    FROM categories
    WHERE categoryID = 4
    UNION ALL
    SELECT c.categoryID, c.name, c.parentID
    FROM categories AS c
    JOIN subtree ON c.parentID = subtree.categoryID)
SELECT *
FROM subtree

However, CTEs are available only in SQLite 3.8.3 or later, which is available only in Android 5.0 or later. In earlier Android versions, you cannot use recursive queries and have to fetch the data of each level separately.

CL.
  • 165,803
  • 15
  • 203
  • 239
  • 1
    Apart from rewriting the query again, is there any other way bu which we can add support for recursive queries in Android API level 20 since the SQLite version 3.8.3 is present in Android 5.0 and it works fine on the same – Parth Doshi Jan 05 '16 at 16:55