difficult query

A place for users and developers of the Xataface to discuss and receive support.

difficult query

Postby cookie720 » Sun Jul 01, 2012 7:32 am

Hi all,
Im trying to display some client details in a pdf of attendances. My table structure is Clients, Matters, Attendances.
Clients can have one to many matters
Matters can have one to many attendances.
I want to see which client is related to the attendance "through" the matters table

SELECT c.FirstName, c.LastName, c.PhoneNumber
FROM clients c
JOIN matters
USING ( ClientID )
JOIN attendances
USING ( MatterID )
When i chuck this __sql__ function into my attendance delegate, i get the following error:
Code: Select all
Fatal error: Failed parsing SQL query on select: SELECT c.FirstName,c.LastName FROM clients c JOIN matters USING ClientID) JOIN attendances USING MatterID . The Error was Parse error: Unexpected clause on line 4 JOIN matters USING ClientID) ^ found: "USING" in C:\wamp\www\live_matters\xataface\lib\SQL\Parser.php on line 1752

when i use the code in phpmyadmin, i do get results, but they are seemingly random: a list of 13 random first and last names of clients.
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm

Re: difficult query

Postby Jean » Mon Jul 02, 2012 6:02 am

Did you try ?
Code: Select all
SELECT c.FirstName, c.LastName, c.PhoneNumber
FROM clients c
NATURAL LEFT JOIN matters
NATURAL LEFT JOIN  attendances
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Re: difficult query

Postby cookie720 » Mon Jul 02, 2012 11:02 pm

almost!!!! im getting the following error:
Code: Select all
Fatal error: Error calculating the number of related records there are for the relationship 'attendances' in the table 'matters'. There was a problem performing the sql query 'SELECT COUNT(*) as num from `dataface__view_attendances_a646ee286fdc48a074f38bd9516e7fbd` as `attendances` where `attendances`.`MatterID` = '0620''. The MYSQL error returned was 'Unknown column 'attendances.MatterID' in 'where clause''.
On line 589 of file C:\wamp\www\live_matters\xataface\Dataface\Record.php in function printStackTrace()
On line 479 of file C:\wamp\www\live_matters\xataface\Dataface\Record.php in function numRelatedRecords(attendances,0)
On line 727 of file C:\wamp\www\live_matters\xataface\Dataface\Record.php in function _loadRelatedRecordBlock(attendances,0,0,0)
On line 3013 of file C:\wamp\www\live_matters\xataface\Dataface\Record.php in function getRelatedRecords(attendances,1,,,0,0)
On line 966 of file C:\wamp\www\live_matters\xataface\Dataface\Record.php in function Dataface_RelationshipIterator(Dataface in C:\wamp\www\live_matters\xataface\Dataface\Record.php on line 589

i have no idea what i did, but i messed around with the view tables in phpmyadmin a few times,(the ones that dataface creates on the fly) and somehow i managed to get client data print to my attendance pdf....but i went to my matter and had a similar error there.

p.s. i have that sql in my attendance delegate class
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm

Re: difficult query

Postby shannah » Wed Jul 04, 2012 10:32 am

It is complaining that the MatterID column doesn't exist. Is this a new column that you have added? It is possible you need to clear the database views (this option is available in the "Control Panel". Upper right link on the page .. then Clear Views).
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: difficult query

Postby cookie720 » Thu Jul 05, 2012 1:15 am

Thanks guys, I no longer need to play around with sql because I just used the same code as shannah gave me in another thread to overcome this problem.
Code: Select all
[clients]
    matters.MatterID="$MatterID"
    clients.ClientID=matters.ClientID


Thanks again shannah!
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 4 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved