REAL SQL Interview Question | Complex SQL Interview Query and Solution

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ม.ค. 2025

ความคิดเห็น • 124

  • @mukesh_moorthy
    @mukesh_moorthy 2 ปีที่แล้ว +2

    You are the best TH-cam channel I have found for clear explanation on sql queries😄

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Thank you Mukesh

  • @SANDATA764
    @SANDATA764 2 ปีที่แล้ว +3

    Mash Allah the lecture really helpful for all IT techs

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +1

      Glad to hear that

    • @SANDATA764
      @SANDATA764 2 ปีที่แล้ว +1

      Please do a complete comprehensive course for sql on udemy platform so
      We can get the maximum benefits .
      Thanks sir

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +1

      I do live sql training on Lighthall.. recorded courses, I may consider in the future

    • @SANDATA764
      @SANDATA764 2 ปีที่แล้ว +2

      @@techTFQ please refer the course link

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +1

      I start next batch from July end ..
      Will announce all detail by this month end

  • @fathimafarahna2633
    @fathimafarahna2633 2 ปีที่แล้ว +1

    Awesome again👍 Masha Allaah👌🏻

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Thank you ❤️

  • @vamsikrishna-yx7xz
    @vamsikrishna-yx7xz 2 ปีที่แล้ว +2

    Awesome. You explained it so nicely and made it simple for us to understand. Great job. Thanks a lot.

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Glad you liked it Vamsi

  • @krishna6296
    @krishna6296 2 ปีที่แล้ว +1

    Thanks for coming up everytime with new problem statements and help us learn something new. Pls keep posting!!

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +1

      Thank you buddy, glad you liked it

  • @travelnexpedition
    @travelnexpedition 2 ปีที่แล้ว +9

    I don’t know why they ask such questions in interview. It doesn’t solve any business problems. Anyways, you did a good job.

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +8

      It’s more about to test your thinking ,
      Even if you are not able to solve it, can you at least understand the logic required and how you go about solving such problems

    • @travelnexpedition
      @travelnexpedition 2 ปีที่แล้ว

      @@techTFQ yes. I think white boarding is ideal. Btw, you are doing a great job. Keep it up!! Love your videos.

  • @divyakamra7830
    @divyakamra7830 2 ปีที่แล้ว +3

    Sir, please make a video on SQL index and it's different types as well it would be really helpful.

  • @mansingmurmu2449
    @mansingmurmu2449 2 ปีที่แล้ว +2

    Thank u so much Sir. Keep uploading

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Your welcome buddy

  • @kotamrajusurya3702
    @kotamrajusurya3702 2 ปีที่แล้ว +1

    really helpful sir thank you very much for your efforts and please keep upload like this type of videos.thank you so much

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +1

      Thank you Surya, I will

  • @aaliyarahman5526
    @aaliyarahman5526 2 ปีที่แล้ว +1

    Thank you Taufeeq 😊

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +1

      Your welcome aaliya

  • @bluesage1528
    @bluesage1528 2 ปีที่แล้ว +1

    Great! Really liked your lesson 👍

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Glad to hear that!

  • @theBATfamiliar
    @theBATfamiliar 2 ปีที่แล้ว +3

    Thank you for sharing man

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Your welcome buddy

  • @asholkkumar4685
    @asholkkumar4685 2 ปีที่แล้ว +2

    Such a great explainer 🙏...

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Thank you Ashok

  • @padhisambit
    @padhisambit 2 ปีที่แล้ว

    Excellent explanation and so helpful !!!!

  • @akashhudge5735
    @akashhudge5735 2 ปีที่แล้ว

    This is really complex query

  • @jamesphillipdeguzman6495
    @jamesphillipdeguzman6495 2 ปีที่แล้ว +3

    I learned something from here. Thanks kind sir. Awesome content as always. Keep uploading more videos like this and maybe next time something that solves a real life business problem as well.

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Thank you James and sure will do!

  • @Sharmasurajlive
    @Sharmasurajlive 2 ปีที่แล้ว +2

    Fantastic brother 👍🏻

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Thank you buddy

  • @AraSh-yn2tt
    @AraSh-yn2tt 2 ปีที่แล้ว +4

    please do a session on how to work with Json and regex in BQ. Thanks!

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +2

      I’ll consider it Ara

    • @Templestarz
      @Templestarz 2 ปีที่แล้ว

      I'm following for this point too. Please create a video for it

  • @jhansiy-f1e
    @jhansiy-f1e 11 หลายเดือนก่อน

    Hi brother how are you? we are learning so many good things about sql you are way of explanation is superb i have a small request can you please do using stored procedures we will learn that process also please

  • @rajkumarrajan8059
    @rajkumarrajan8059 ปีที่แล้ว

    This is amazing!!!

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      Thank you very much 😊

  • @ramchand1019
    @ramchand1019 ปีที่แล้ว

    Hi mentor, it was pleasure to subscribe your channel.. I m learning sql every nook and corner of the logic..im really grateful to come across ur channel... Thank u so much.. I have a doubt.. I'm 33 .im reforming my career in data analytics...could u share ur opinion

  • @Shubh_Vaghela
    @Shubh_Vaghela ปีที่แล้ว +1

    Hey TFQ, thanks for this great explanation
    Let me also share you my solution for the same problem
    I don't know if it is good practice or not but I tried to solve it differently and it worked
    CREATE TABLE #temp_table (
    Person_id NVARCHAR(1000)
    , Relative_id_1 NVARCHAR(1000)
    , Relative_id_2 NVARCHAR(1000)
    )
    INSERT INTO #temp_table
    VALUES
    ('ATR-1',null,null),
    ('ATR-2','ATR-1',null),
    ('ATR-3','ATR-2',null),
    ('ATR-4','ATR-3',null),
    ('ATR-5','ATR-4',null),
    ('BTR-1',null,null),
    ('BTR-2',null,'BTR-1'),
    ('BTR-3',null,'BTR-2'),
    ('BTR-4',null,'BTR-3'),
    ('BTR-5',null,'BTR-4'),
    ('CTR-1',null,'CTR-3'),
    ('CTR-2','CTR-1',null),
    ('CTR-3',null,null),
    ('DTR-1','DTR-3','ETR-2'),
    ('DTR-2',null,null),
    ('DTR-3',null,null) ,
    ('ETR-1',null,'DTR-2'),
    ('ETR-2',null,null),
    ('FTR-1',null,null),
    ('FTR-2',null,null),
    ('FTR-3',null,null),
    ('GTR-1','GTR-1',null),
    ('GTR-2','GTR-1',null),
    ('GTR-3','GTR-1',null),
    ('HTR-1','GTR-1',null),
    ('HTR-2','GTR-1',null),
    ('HTR-3','GTR-1',null),
    ('ITR-1',null,null),
    ('ITR-2','ITR-3','ITR-1'),
    ('ITR-3',null,null);
    --SELECT * FROM #temp_table
    CREATE TABLE #temp_data ( grp NVARCHAR(10) , family NVARCHAR(1000) )
    INSERT INTO #temp_data
    SELECT SUBSTRING(Person_id,1,1) as grp , Person_id
    FROM #temp_table
    WHERE Person_id is not null and Relative_id_1 is not null and Relative_id_2 is not null
    UNION
    SELECT SUBSTRING(Person_id,1,1) as grp , Relative_id_1
    FROM #temp_table
    WHERE Person_id is not null and Relative_id_1 is not null and Relative_id_2 is not null
    UNION
    SELECT SUBSTRING(Person_id,1,1) as grp , Relative_id_2
    FROM #temp_table
    WHERE Person_id is not null and Relative_id_1 is not null and Relative_id_2 is not null
    UNION
    SELECT SUBSTRING(Relative_id_1,1,1) as grp , Person_id
    FROM #temp_table
    WHERE Person_id is not null and Relative_id_1 is not null and Relative_id_2 is null
    UNION
    SELECT SUBSTRING(Relative_id_1,1,1) as grp , Relative_id_1
    FROM #temp_table
    WHERE Person_id is not null and Relative_id_1 is not null and Relative_id_2 is null
    UNION
    SELECT SUBSTRING(Person_id,1,1) as grp , Person_id
    FROM #temp_table
    WHERE Person_id is not null and Relative_id_1 is null and Relative_id_2 is not null
    UNION
    SELECT SUBSTRING(Person_id,1,1) as grp , Relative_id_2
    FROM #temp_table
    WHERE Person_id is not null and Relative_id_1 is null and Relative_id_2 is not null
    --SELECT * FROM #temp_data
    SELECT grp , STRING_AGG(family,',') WITHIN GROUP(ORDER BY family) as family
    INTO #temp_data_2
    FROM #temp_data
    GROUP BY grp
    UNION
    SELECT SUBSTRING(a.Person_id,1,1) as grp, a.Person_id
    FROM #temp_table a
    LEFT JOIN #temp_data b ON a.Person_id = b.family
    WHERE b.family IS NULL
    SELECT 'F_' + CONVERT(NVARCHAR(10),ROW_NUMBER() OVER(ORDER BY grp)) as Family_id, family as Relatives
    FROM #temp_data_2
    DROP TABLE #temp_table
    DROP TABLE #temp_data
    DROP TABLE #temp_data_2

  • @sheikhsheharyar6178
    @sheikhsheharyar6178 2 ปีที่แล้ว

    Toufeeq i would appreciate if you start making videos on cosmos DB

  • @VishalSharma-hv6ks
    @VishalSharma-hv6ks 2 ปีที่แล้ว

    Very Interesting

  • @arunv1909
    @arunv1909 2 ปีที่แล้ว +2

    awesome thank you , also pls share how real time scenarios will be

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +1

      You mean the sql we write in our jobs is it ?

    • @arunv1909
      @arunv1909 2 ปีที่แล้ว +1

      @@techTFQ yes

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +1

      noted, will plan something on this

  • @buak809
    @buak809 ปีที่แล้ว

    I'm not fully positive about FTR-1, FTR-2, FTR-3 but I tihnk you could return them by using LEFT JOIN clause rather than JOIN in line 6

  • @nageshk9100
    @nageshk9100 2 ปีที่แล้ว

    Very good videos ..

  • @NTR898
    @NTR898 2 ปีที่แล้ว +2

    Can you please do video on using joins along with Aggregate functions ,where having ,group by order by

    • @arunv1909
      @arunv1909 2 ปีที่แล้ว +1

      do check his channel, he has already posted that

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +1

      As Arun said, the video is already made, plz check my channel

  • @aperxmim
    @aperxmim 2 ปีที่แล้ว +2

    I am going to try to solve in Microsoft SQL Server

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Nice.. good luck

  • @theresepraisethelord201
    @theresepraisethelord201 ปีที่แล้ว

    Can you do any healthcare example please for people who works with hospital data

  • @sachingunjal7347
    @sachingunjal7347 ปีที่แล้ว

    Hi Taufiq, thanks for the detailed explenation , i Guess you mentioned incorrect blog link as I am not able to see table queries.
    Namaste, Sachin

  • @its_mahiiii
    @its_mahiiii 2 ปีที่แล้ว +1

    Hello, please make video o how to download mysql or oracle in windows to practise queries in our local please.Thanks.

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +1

      there are several videos on youtube which show this.
      I do not have a windows computer else I could have made a video about it

  • @ishukumar2041
    @ishukumar2041 2 ปีที่แล้ว +2

    hi brother can you please let me know when are you going to start new batch?

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Sure bro, I’ll announce it 1 month prior to the start of class.. probably class starts from end of July

  • @bk320929
    @bk320929 2 ปีที่แล้ว +1

    Thanks for the situation and solution. But I was wondering how it can be done in Oracle to avoid recursive loop, any ideas?

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      do you mean how to do this without using recursive sql in oracle?

    • @bk320929
      @bk320929 2 ปีที่แล้ว

      @@techTFQ I was trying same in Oracle but was getting recursive loop error (ORA-32044). Tried cycle par set is_loop to 'Y' default 'N' (not sure if this helps) which didn't worked anyway.

  • @kentondang962
    @kentondang962 2 ปีที่แล้ว

    You can just join the main table with the base query cte to get the group of people relatives, dont need to do recursive there.

  • @prudhvireddy5026
    @prudhvireddy5026 2 ปีที่แล้ว

    Hi sir, when will you start live sessions

  • @pawansahu167
    @pawansahu167 2 ปีที่แล้ว +1

    Hi Taufiq.. Thanks for wonderful explanation. I have been trying same code with SQL server but getting error on recursive table "related_fam_members;

  • @kancharalaparameshwarreddy3837
    @kancharalaparameshwarreddy3837 2 ปีที่แล้ว

    sir plz provide video on views and indexes last video i never wont ask agin sir plzzzzzzzz

  • @sandeepkumar-ol5lg
    @sandeepkumar-ol5lg 2 ปีที่แล้ว

    Hi, Could you please explain what’s the best way to write conditions in WHERE clause

  • @sandrahu7122
    @sandrahu7122 2 ปีที่แล้ว

    I got confused here. is it that we always start from the base(anchor) query and then the recursive part? but this example puts the cursive first.

  • @sureshkumar-ou2fb
    @sureshkumar-ou2fb ปีที่แล้ว

    SIR.. I HAVEA DOUBT 21:30 "FAM_GROUP" IS ONLY IN BASE QUERY RIGHT!! HOW CAN U TAKE THAT FROM RELATED FAM_MEMBERS? PLS EXPLAIN.. (IF IN TAMIL MEANS EVEN MOST SUPPORT)

  • @krishnapriya7045
    @krishnapriya7045 2 ปีที่แล้ว

    Hi bro can u plz upload videos on GCP

  • @manojt7012
    @manojt7012 2 ปีที่แล้ว

    Seems the similar query doesn't works with MSSQL. When I tried out the query is running in an endless loop though I had this joining condition...
    should we take only single record in base query and try the JOINS?

  • @somethingnew9627
    @somethingnew9627 2 ปีที่แล้ว

    Hi one request can you add the ms sql query also for this. Becoming kind of confusing.

  • @KiranKumar-hk5ji
    @KiranKumar-hk5ji 2 ปีที่แล้ว

    Sir can we use case statement to merge these 2columns into column3 and the. Work the solution

  • @tonysun203
    @tonysun203 2 ปีที่แล้ว +1

    Hi Thoufiq. Thanks for your sharing. I notice that you are putting the base query "base_query" at the end and put the recursive query "related_fam_memebers" at the beginning. However, you are still able to use the base query in your recursive query. Does it mean that we can place our query in the with clause anywhere (at the beginning or end), we can still use the query in that with clause statement ? The ordering still does not matter.

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      Good question Tony and this depends on the RDBMS.
      In PostgreSQL, the order of temp tables do not matter but I know in SQL server or some other RDBMS does not support this.

    • @sureshkumar-ou2fb
      @sureshkumar-ou2fb ปีที่แล้ว

      @@techTFQ what to do if that base_query does not support at top??
      Mysql does not support this...im stuck now..

  • @tousifalisarwan5130
    @tousifalisarwan5130 2 ปีที่แล้ว +1

    First view

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว +2

      Thanks buddy

  • @redwannabil8031
    @redwannabil8031 2 ปีที่แล้ว

    Is there any alternative way to solve recursive sql queries?? And could you please provide some examples

  • @prakashmallick6768
    @prakashmallick6768 2 ปีที่แล้ว

    Yes I'm using mode M and also I facing problem at the time of solving this query..please help me

  • @MrAithal29688
    @MrAithal29688 8 หลายเดือนก่อน

    Link to the blog is not working any more. Could you please help update ?

  • @amitshrivas1974
    @amitshrivas1974 2 ปีที่แล้ว +1

    But this Query solve to inner join also
    Am i right ?

    • @techTFQ
      @techTFQ  2 ปีที่แล้ว

      sorry, dint get you bro.
      are you asking if we can solve it using inner join alone?

    • @amitshrivas1974
      @amitshrivas1974 2 ปีที่แล้ว

      @@techTFQ yes

  • @toxic_ninja_6964
    @toxic_ninja_6964 2 ปีที่แล้ว +1

    bhai DVD ki full form digital video disk ha

  • @rajanadar3835
    @rajanadar3835 ปีที่แล้ว

    sir can you give code for mysql rdbms also?

  • @kancharalaparameshwarreddy3837
    @kancharalaparameshwarreddy3837 2 ปีที่แล้ว

    This week any video sir

  • @Gate_Tricks
    @Gate_Tricks 2 ปีที่แล้ว

    hi bro... please clear me that...
    what is data monkey and can a person jump from data monkey job to data science and data analytics.... please reply

  • @venkatesh2285
    @venkatesh2285 2 ปีที่แล้ว

    Dear sir, do IT companies hire 35years old people with 2year gap as a fresher if he or she have strong technical skills( in coding) as a full stack developer .. please reply..

  • @mahadevraosonekar3108
    @mahadevraosonekar3108 2 ปีที่แล้ว

    Sir can you pleaseexplain this query display the query having count more than 4 , cost price not between 4 and 5 thousand

  • @rajkumarrajan8059
    @rajkumarrajan8059 ปีที่แล้ว

    Hi,
    Recursive Query available in SQL Server?

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      Yes it is

  • @ismailmerahbaoui
    @ismailmerahbaoui ปีที่แล้ว

    I think you're wrong cause the prblm is to combain person one to relative 1 and relative to to person 1 cos it relative to 2 .So let's just say there is another row with the following data person:ATR-7 relative1:ATR-8 and relative2 is null basically your query will put them along the atr family or F1 although they're not related to it so pls anybody explain me if am wrong

  • @muskaansharma4833
    @muskaansharma4833 2 ปีที่แล้ว

    Sir if we have first name,last name and age and we have write a query where first name = Robert and lastname= Smith and sortby age how to write it sir please help

    • @Tidbit0123
      @Tidbit0123 2 ปีที่แล้ว

      in oracle DB
      SELECT
      first_name,
      last_name,
      age
      FROM table_name
      WHERE lower(first_name) = 'robert'
      AND lower(last_name) = 'smith'
      ORDER BY age;

  • @TheDataMagic_x
    @TheDataMagic_x 27 วันที่ผ่านมา

    I just asked one qns could you help me sir

  • @anujgupta8686
    @anujgupta8686 2 ปีที่แล้ว

    This is not working in TSQL mssql server.

  • @vishwanath-ts
    @vishwanath-ts 10 หลายเดือนก่อน

    Link not working

  • @vinothvk2711
    @vinothvk2711 ปีที่แล้ว

    in sql server i ran the same query, recursive goes in infinite loop.Any idea ?
    with related_fam_members as
    (select * from (
    select relative_id1 as relatives, substring(person_id,1,3) as family_group
    from family_members where relative_id1 is not null
    union
    select relative_id2 as relatives, substring(person_id,1,3) as family_group
    from family_members where relative_id2 is not null) base_query
    union all
    select fam.person_id, r.family_group
    from related_fam_members r
    join family_members fam on fam.relative_id1 = r.relatives or relative_id2 = r.relatives
    )
    select * from related_fam_members
    option(maxrecursion 10000)

    • @vinothvk2711
      @vinothvk2711 ปีที่แล้ว

      Any answers ? Im curious to know about it

  • @Sumedh2011
    @Sumedh2011 2 ปีที่แล้ว +1

    Hi Taufiq, how can we use CONNECT BY PRIOR clause for the said requirement in case of Oracle? Or perhaps any other technique in Oracle DB?

  • @vikramjitsingh6769
    @vikramjitsingh6769 ปีที่แล้ว

    with recursive final_query as ( ( select relative_id1 as rel1, substring(person_id,1 , 3) as fam from family_members
    where relative_id1 is not null union select relative_id2 as rel1, substring(person_id,1 , 3) as fam from family_members where relative_id2 is not null order by 1) union
    (select m.person_id , f. fam from final_query f join family_members m on m.relative_id1 = f.rel1 or m.relative_id2 = f.rel1 ) ),
    nofamily as (select person_id from family_members where relative_id1 is Null and relative_id2 is null and person_id not in (select rel1 from final_query))
    select *, concat("F_",row_number() over(order by family)) from
    ((select distinct group_concat(rel1 separator ',') as family from final_query
    group by fam order by 1)
    union all
    (select * from nofamily)
    order by 1) as x

  • @katkatduoadventures5711
    @katkatduoadventures5711 2 ปีที่แล้ว

    ATR2 is related to ATR1 but ATR1 is not related to ATR2 :D

  • @rohitsethi5696
    @rohitsethi5696 ปีที่แล้ว

    where is code

  • @narasimhamurty859
    @narasimhamurty859 2 ปีที่แล้ว

    you are getting ATR-1 ,BTR-1, DTR-2 ,DTR-3,CTR-3,ITR-1 by just joining , how is it possible? because both of the relative_id's are null right ?AND those id's present in the other table column values in the table.
    if what i am saying is right then what is the logic to get those respective person_id?

    • @naveenroyal5817
      @naveenroyal5817 ปีที่แล้ว

      Because in with clause after base query you can see the union, so as taufqi said, base query will only excute at once, at first time the base query out has the out of relative _id1 union relative_id2. So, art1 will be there.

  • @babyshalinishalu7252
    @babyshalinishalu7252 2 ปีที่แล้ว

    Hi

    • @babyshalinishalu7252
      @babyshalinishalu7252 2 ปีที่แล้ว

      I wanted to know output for 1 table
      Create table patient (p_id int, p_name varchar(100),visits varchar(100));
      Insert into patient select 1, 'raj', 'V1' from dual;
      Insert into patient select 1, 'raj', 'V3' from dual;
      Insert into patient select 1, 'raj', 'V4' from dual;
      Insert into patient select 2, 'divya', 'V2' from dual;
      Insert into patient select 2, 'divya', 'V4' from dual;
      Hw to write query for missed records for visits
      Eg: for p_id 1 visits column v2 is missing hw to fetch query

  • @22_vamshikrishnadathrika31
    @22_vamshikrishnadathrika31 2 ปีที่แล้ว

    Hi Taufiq. while I'm solving this code in ms sql server it is giving an error like this:
    "The statement terminated. The maximum recursion 100 has been exhausted before statement completion."
    do you know any the reason

    • @22_vamshikrishnadathrika31
      @22_vamshikrishnadathrika31 2 ปีที่แล้ว

      what is the terminating condition do we have to use

    • @swtannie19
      @swtannie19 2 ปีที่แล้ว

      @@22_vamshikrishnadathrika31 did you get the solution? I'm facing the same issue in sql server

    • @vamshidathrika8907
      @vamshidathrika8907 2 ปีที่แล้ว

      No

  • @udaykumar-tb5kn
    @udaykumar-tb5kn 2 ปีที่แล้ว

    What is your sql fees
    Pls tell me when new batch will be started??

  • @rohitsharma-mg7hd
    @rohitsharma-mg7hd 5 หลายเดือนก่อน +1

    DROP TABLE IF EXISTS public.relatives;
    CREATE TABLE IF NOT EXISTS public.relatives
    (
    PERSON_ID text,
    RELATIVE_ID1 text,
    RELATIVE_ID2 text
    );
    INSERT INTO relatives
    VALUES (
    ('ATR-1',NULL,NULL),
    ('ATR-2','ATR-1',NULL),
    ('ATR-3','ATR-2',NULL),
    ('ATR-4','ATR-3',NULL),
    ('ATR-5','ATR-4',NULL),
    ('BTR-1',NULL,NULL),
    ('BTR-2',NULL,'BTR-1'),
    ('BTR-3',NULL,'BTR-2'),
    ('BTR-4',NULL,'BTR-3'),
    ('BTR-5',NULL,'BTR-4'),
    ('CTR-1',NULL,'CTR-3'),
    ('CTR-2','CTR-1',NULL),
    ('CTR-3',NULL,NULL),
    ('DTR-1','DTR-3','ETR-2'),
    ('DTR-2',NULL,NULL),
    ('DTR-3',NULL,NULL),
    ('ETR-1',NULL,'DTR-2'),
    ('ETR-2',NULL,NULL),
    ('FTR-1',NULL,NULL),
    ('FTR-2',NULL,NULL),
    ('FTR-3',NULL,NULL);