I am new in SQL and I am trying to do a recursive query over the same table to find the brokers of the "master brokers" I have a table that looks like this (it can grow to any amount of rows and deepness)
So I need a result like this:
master_id => broker_id
I have checked about how to do it and I got:
WITH admin_has_master_brokers
AS (
SELECT DISTINCT master_broker_id, admin_id
FROM admin_has_master_brokers
UNION ALL
/*I DO NOT KNOW HOW TO DO THIS SECTION*/
SELECT
master_broker_id, admin_id
FROM admin_has_master_brokers
)
SELECT
*
FROM
admin_has_master_brokers
ORDER BY master_broker_id ASC
But I can not understand how to do the recursive part to only get the results I need because I am getting this:
Any idea?


