0

select statements

Hi everybody

It's been known that select statements are rather demanding from the server, so it's best not to use too many of them at the same time. I'm trying to streamline my database and was wondering if it makes a difference if the select statement refers to a different table rather than to a child table.

E.g.: 

let varA := 'distance';
first((select 'Child')[miles = varA].bike)

Versus:

let varA := 'distance';
first(select 'Sister table'[miles = varA].bike)

If indeed it makes a difference, it would make sence to make this sister table a child instead of a sister.

Or maybe there is another way to retrieve the data from the child table which is even less demanding?

Thanks for your insights!

5 replies

null
    • Fred
    • 11 days ago
    • Reported - view

    You are correct that you should always try to limit the use of selects. If possible use the record() command or reference fields.

    If you are looking into a child table and only want related records then you can skip the select and just use the reference field name (which by default is the table name).

    If I have the following structure:

    Table1
       Child1
    Table2

    If I'm in Table1 I can always refer to the Child1 table with just:

    Child1

    So for your example it would be:

    let varA := 'distance';
    first(Child[miles = varA].bike))

    This tells Ninox to use the reference field Child and then look at all of the linked records where miles = varA.

    Your previous code:

    let varA := 'distance';
    first((select 'Child')[miles = varA].bike)
    

    Will find all records in Child where miles equals varA regardless if it is related to the parent record.

    I hope this helps.

    • Jarno_Vande_Walle
    • 9 days ago
    • Reported - view

    indeed, this works better, Fred. Thanks!

      • Fred
      • 9 days ago
      • Reported - view

      When you get a chance, please mark the post "answered"

      • Jarno_Vande_Walle
      • 9 days ago
      • Reported - view

       I believe this feature is only possible in the "get help-section", not in the "learn and share", otherwise I would have done it immediately.

      • Fred
      • 9 days ago
      • Reported - view

      you are correct. I didn't see that this was not posted in the get help section.