Yash-cor commented on issue #35164:
URL: 
https://github.com/apache/shardingsphere/issues/35164#issuecomment-2803841494

   > Hi [@Yash-cor](https://github.com/Yash-cor), can you explain the meaning 
of this sql - `WITH RECURSIVE cte AS ( SELECT * from t_user UNION ALL SELECT 
user_id+1, name FROM cte WHERE user_id < 5 ) SELECT * FROM cte`?
   
   Ok so t_user is the physical table which exists in our database and it 
contains two columns `user_id` and `name`.
   By using the RECURSIVE segment we can apply recursion in our queries to 
create temporary table.
   
   RECURSIVE subquery contains two parts one non recursive part - `SELECT * 
from t_user`
   Other is recursive part - `SELECT user_id+1, name FROM cte WHERE user_id < 5`
   In recursive part we have to use the same common table expression alias 
table.
   
   And it is necessary to combine them with UNION.
   
   For Example if t_user contains  - (1, 'Yash').
   
   Now this part starts using the rows from cte (which initially has just (1, 
'Yash')) and will keep generating:
   
   (2, 'Yash')
   
   (3, 'Yash')
   
   (4, 'Yash')
   
   (5, 'Yash')
   
   Because the condition is user_id < 5, it stops once user_id becomes 5.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to