Questions tagged [recursive-query]

The ability to run recursive queries in SQL

Recursive SQL queries offer the ability to retrieve hierarchical information in a relational database (e.g. "adjacency list model"). The SQL standard defines recursive common table expressions (CTE) for this purpose. Some vendors such as Oracle have implemented this functionality with a proprietary syntax (CONNECT BY). Recursive CTEs are supported by a wide range of DBMS such as Oracle, SQL Server, DB2, PostgreSQL, Firebird SQL, Teradata and others.

2024 questions
0
votes
1 answer

try to run recursion function in python but it will retun non for v1 and v2

v1 = ['hi', 'hello', 'this', 'that', 'is', 'of'] v2 = {"Hamza": 1, "Kashif": 2, "Ali": 3} v3 = "I love pakistan." def rec(value): if isinstance(value, list): for i in value: rec(i) elif isinstance(value, dict): for…
DS_Hamza
  • 1
  • 2
0
votes
0 answers

CONNECT BY (Oracle) relevan in PostgreSQL without RECURSIVE

all, I have logic in Oracle and should migrate to PostgreSQL. But the version of PostgreSQL doesn't support "with recursive" it's v.8.3. Can you help me? BR Oracle logic: select t1.re_id from ib_re t1, ib_re_usage t2 Where t1.re_id = t2.re_id …
Septiana Fajrin
  • 123
  • 1
  • 3
  • 10
0
votes
0 answers

Recursive N-Level MySQL Query

I'm trying to build url's from Word Press Post/Pages. I'm able to connect to the database and retrieve the data I need. However some pages have parents, which are just other pages, for example: |id|post_name|post_parent|post_status|url |1 |post_1 …
markpirvine
  • 1,485
  • 1
  • 23
  • 54
0
votes
1 answer

Select query on a Hierarchy Table PostgreSQL

I was trying to make a recursive select query in postgreSQL, I tried to read a few articles but I couldn't really get the solution out of them... either it's multi-table hierarchy or on another dialect to which then I can't translate to Postgres.…
L_Cleo
  • 1,073
  • 1
  • 10
  • 26
0
votes
1 answer

MS SQL recursively get child id with parent ids

I have created a search SQL query, I'm almost finished I only need to match the WHERE clause with an id and it's parent ids. Currently I only match with an id and not it's parents. I'm not sure how to solve this. This is my query, the code where I…
0
votes
2 answers

Working days of month until current date in PostgreSQL

I want to get the number of working days of the month until current date over time in PostgreSQL. For example, this month until today, working days is 17. How can I obtain this from the query below or a general solution? SELECT TO_CHAR(i,…
kimi
  • 525
  • 5
  • 17
0
votes
1 answer

Tricky CTE - recursive sql (editing my query)

I want to edit my query in order to get something a little more ticky. The goal is to obtain the approval workflow for every customer, displaying that information in this way: CLIENT | APPROVER1 | APPROVER2 | APPROVER3 | APPROVER4 Previously, i…
JustToKnow
  • 785
  • 6
  • 23
0
votes
2 answers

Traversing a given path on a tree with labelled nodes

Suppose that we have a tree with labelled nodes where each node has a unique id and a non-unique label. A path on the tree can be described by an ordered set of labels; eg., with a path descriptor, P = ['', 'a', 'a.1', 'a.1.3'] = "/a/a.1/a.1.3"…
AlQuemist
  • 1,110
  • 3
  • 12
  • 22
0
votes
0 answers

How do I connect a hierachical query by a substring of the prior record

So essentially I have hierarchical data saved to a table with the standard parent/ child relationship. I want to remove part of the child's name (for example the first letter) and use that to connect to the next level. Example: Each Parent has a…
0
votes
1 answer

Recursion - chaining data in sql - stuck

I have different tables and the goal is to obtain the approval workflow for every customer Customers have different approval workflows, take a look at this: In my table "entities" i have this (12, 'Math Andrew', 308, 'CHAIN1-MathAndrew'). It means…
JustToKnow
  • 785
  • 6
  • 23
0
votes
1 answer

How to write recursive SELECT statements

I have a table of ID's of some books. The table is called prequel and has two columns: "resid" and "prequelid". If a pair of ID's is present as a row in this table it means that the "prequelid"-value is the prequel of the "resid"-value. How can I…
user12095666
0
votes
1 answer

Data Structures recurrence relation

I need help and your tips to answer this kind of question because I'm lost... this is the question: there are n letters, each letter has its box mail. f(n) = the number of ways to put every letter in the wrong box mail. I need to find a recursive…
Zamkie
  • 97
  • 1
  • 6
0
votes
1 answer

Only keep first value of first column and sort the two other columns according to hierarchy

So five people work at the Laugh factory. Marc is up first, then Judy, then Lorie, then Agnes and lastly, Isaiah. I want to go from this: +------------------------------+ | Laugh Factory |Marc | Judy | | Laugh Factory |Judy | Lorie | | Laugh…
0
votes
1 answer

Renumber table rows with a recursive statement

To understand the behaviour of recursion (in SQLite), I tried the following statements to re-number the rows of a table with a recursive statement: Let's create a sample table, CREATE TABLE tb (x TEXT(1) PRIMARY KEY); INSERT INTO tb VALUES…
AlQuemist
  • 1,110
  • 3
  • 12
  • 22
0
votes
3 answers

Lazy upward recursive query in sql

I'm trying to generate a path from the name of an item's parents. For example if test has for parent dad the path would be dad/test; and if dad had for parent gran the path of test would be gran/dad/test. I only have the id of the child, so far I…
Hugo
  • 349
  • 3
  • 6
  • 23