Page 1 of 1

Accessing Join fields

Posted: 07.07.2006, 17:35
by yoda
greetings,
I am running Delphi 6 with Zeoslib 6.1.5-stable and Mysql.

I have a TZQuery component on my form and have added SQL code
to the SQL property of the TZQuery component.

Normally I reference a field by using someting like:

MyQuery.fieldbyname('name').asstring

Well, I gone and used a join in my SQL code and don't know how to
reference a field ?

ie, select dealer.dnum, dealer.name,mixtemp.name from dealer left join
mixtemp on dealer.dnum = mixtemp.dnum

can't reference fields like
MyQuery.fieldbyname('dealer.dnum').asstring
as that gives a big error.

How do you do it ?

thanks,
D

Posted: 07.07.2006, 21:24
by mdaems
Use an alias for your field names like this:

Code: Select all

select dealer.dnum d_dnum, dealer.name d_name,mixtemp.name m_name from dealer left join mixtemp on dealer.dnum = mixtemp.dnum
Then you can do

Code: Select all

MyQuery.fieldbyname('d_dnum').asstring
Mark

Posted: 07.07.2006, 21:46
by zippo
I use joined tables avery day and I always just state the name of the field after the word "Select". In your example:

Code: Select all

MyQuery.fieldbyname('dnum').asstring;
It has always worked OK for me. Post here if the tip os OK or not!

Posted: 08.07.2006, 11:04
by mdaems
That tip is OK as long as there are noduplicate field names, as is the case here.

Posted: 08.07.2006, 11:14
by zippo
That's right. But I always use different field names... :)
And for the example it should work.