I'm new to nuBuilderPro. I'm trying to join a table with itself within a form SQL source, but I get errors with it. Here's the code:
Code: Select all
SELECT trainees.firstname, trainees.lastname, payers.lastname AS 'payer'
FROM clients trainees
INNER JOIN clients payers ON trainees.payerid = payers.id
WHERE (trainees.dou = '0000-00-00' or trainees.dou IS NULL) and trainees.class IS NOT NULL
Code: Select all
===USER==========
globeadmin
===PDO MESSAGE===
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous
===SQL===========
SELECT id,IFNULL(firstname,''),IFNULL(lastname,''),IFNULL(REPLACE(FORMAT(occupationid,0), ",", ""),''),IFNULL(class,''),IFNULL(REPLACE(FORMAT(payerid,0), ",", ""),''),IFNULL(address,''),IFNULL(DATE_FORMAT(dob,"%d-%b-%Y"),''),IFNULL(DATE_FORMAT(dor,"%d-%b-%Y"),''),IFNULL(DATE_FORMAT(dou,"%d-%b-%Y"),''),IFNULL(phone,''),IFNULL(mobile,''),IFNULL(notes,'') FROM clients trainees INNER JOIN clients payers ON trainees.payerid = payers.id WHERE (trainees.dou = '0000-00-00' or trainees.dou IS NULL) and trainees.class IS NOT NULL
===BACK TRACE====
/var/www/dev-hapkidonet/nuapi.php - line 1943 (nuRunQuery)
/var/www/dev-hapkidonet/nuapi.php - line 1619 (nuGetBrowseRecords)
/var/www/dev-hapkidonet/nuapi.php - line 183 (nuGetBrowseForm)
I have tried to replace "...FROM clients trainees INNER JOIN clients payers..." with "...FROM clients AS trainees INNER JOIN clients AS payers...", but no luck.
The reason of this "complex" design is that a trainee can be a payer at the same time. So, to avoid duplicate records, I made a table 'clients' and put both trainees and payers in there.
The same SQL query runs without a problem in phpMyAdmin and gives results.
Any thoughts on this?
Thanx!