1

my target is to find the highest position in hierarchy. I have provided video below for better explanation.

This is the current query I am running:

SELECT * FROM 'agent_heirarchy' WHERE 'user_id'=370524;   / 
          SELECT * FROM 'agent_heirarchy' WHERE 'id'= 24273;      / this is the parent id of 370524
          SELECT * FROM 'agent_heirarchy' WHERE 'id'= 301;       / this is the parent id of 24273. 

The query will stop here because the parent id of 301 is null. // It will only stop when the parent id is = Null

Video of what I'm currently doing: https://streamable.com/51zxzi

So my final target is, is there a way where i can run a much easier query than what i'm currently doing?

Jake G
  • 55
  • 5
  • Videos are not safe/useful/applicable. Provide: precise MySQL version, sample data as CREATE TABLE + INSERT INTO formatted textual scripts (or create online fiddle), desired output for this data. – Akina Jan 21 '21 at 05:05
  • Does this answer your question? [Retrieve top-level parent MySQL](https://stackoverflow.com/questions/22169281/retrieve-top-level-parent-mysql) – kmoser Jan 21 '21 at 05:10
  • I'm confused. This isn't MySQL. – Strawberry Jan 21 '21 at 08:07
  • I'm sorry guys, I'm really newbie to this. However, Can i use the result as a variable in query? Thank you – Jake G Jan 21 '21 at 09:24

0 Answers0