Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

A Browse form containing a JOIN

Questions related to using nuBuilder Forte.
Post Reply
absalom
Posts: 25
Joined: Sat Apr 03, 2021 3:50 pm

A Browse form containing a JOIN

Unread post by absalom »

Hi, as soon as I add a JOIN clause in my SQL request (browse FORM), it stops working (no record is returned); if I remove the clause (and the relevant fields to be displayed) I get the expected rows.

How can I handle this clause?
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 447 times
Contact:

Re: A Browse form containing a JOIN

Unread post by kev1n »

Can you post your SQL?
absalom
Posts: 25
Joined: Sat Apr 03, 2021 3:50 pm

Re: A Browse form containing a JOIN

Unread post by absalom »

My SQL is:

Code: Select all

SELECT consultations.date, patients.nom, patients.prenom, consultations.type, consultations.prix, consultations.type_reglement
  FROM consultations JOIN patients ON consultations.id_patient = patients.id
  WHERE consultations.date_encaissement IS NULL
ORDER BY consultations.date DESC
Result is as expected on phpMyAdmin
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 447 times
Contact:

Re: A Browse form containing a JOIN

Unread post by kev1n »

Make sure that the column names in the column Display are written exactly as in the SELECT statement.
sql.png
If you press CTRL+SHIFT+I (Options Menu -> Form Info) you will see the generated SQL.
You do not have the required permissions to view the files attached to this post.
absalom
Posts: 25
Joined: Sat Apr 03, 2021 3:50 pm

Re: A Browse form containing a JOIN

Unread post by absalom »

Both tables have 'id' as their primary key fields, and the generated SQL tries to select the ambiguous field 'id'.

Do I have to change the name of my column in the database and fix the change everywhere in NuBuilder, or can I still do it as it?
absalom
Posts: 25
Joined: Sat Apr 03, 2021 3:50 pm

Re: A Browse form containing a JOIN

Unread post by absalom »

Finally did it by creating a view with the JOIN instead
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 447 times
Contact:

Re: A Browse form containing a JOIN

Unread post by kev1n »

Could could try a SELECT ... FROM ... SELECT:

Code: Select all

SELECT date, nom, prenom, type, prix, type_reglement FROM (
SELECT consultations.id, consultations.date, patients.nom, patients.prenom, consultations.type, consultations.prix, consultations.type_reglement
  FROM consultations JOIN patients ON consultations.id_patient = patients.id
  WHERE consultations.date_encaissement IS NULL
) T
ORDER BY consultations.date DESC
Post Reply