How to use JOIN command in MySql.LIB?*Understood/More Clear*

Post Reply
User avatar
dutch
Posts: 1395
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

How to use JOIN command in MySql.LIB?*Understood/More Clear*

Post by dutch »

I try with JOIN command but it doesn't successful. How can I use it?

Code: Select all

local cServer := 'localhost'
local cUser   := 'root'
local cPassword := '123456'
local cDbName   := 'easyfo'

oSvr := TMySqlServer():New(cServer,cUser,cPassword)
oSvr:SelectDb( cDbName )

oDb1 := oSvr:Query("SELECT * FROM ccrtbl LEFT JOIN ccrgst ON ccrtbl.tbl_gstno=ccrgst.gst_intno")
Last edited by dutch on Wed Jun 24, 2015 4:49 am, edited 2 times in total.
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: How to use JOIN command in MySql.LIB?

Post by AntoninoP »

Hi,
have you problem with the join command in general?
It depends on what result you want and on tables structures.
Have you try the select command in a another context?
Take a look a those pages, They explain Join command very well:
http://www.w3schools.com/sql/sql_join.asp
http://www.codeproject.com/Articles/330 ... -SQL-Joins
Hope I am helping,
Regards,
Antonino Perricone
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: How to use JOIN command in MySql.LIB?

Post by Enrico Maria Giordano »

Dutch,
dutch wrote:

Code: Select all

SELECT * FROM ccrtbl LEFT JOIN ccrgst ON ccrtbl.tbl_gstno=ccrgst.gst_intno
The query syntax looks ok. What error do you get?

EMG
User avatar
dutch
Posts: 1395
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to use JOIN command in MySql.LIB?

Post by dutch »

Dear Antonio and EMG,

I've read the JOIN statement from http://www.w3schools.com, it is quite simple.
I can ::Query one by one in a few seconds without problem. I try to JOIN (SET RELATION TO) for CCRTBL and CCRGST. It doesn't show (wait for long time more than 5 minutes and I terminate in Task manager).
I'm not quite sure, what is the problem? Can I use this statement with MySql.Lib, LibMySql.Lib?

Thanks for kind help.
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
Adolfo
Posts: 815
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile
Contact:

Re: How to use JOIN command in MySql.LIB?

Post by Adolfo »

Dutch.. you must be more specific..

1.- Are the tables 1 to 1.... 1 Record in ccrtbl and 1 record in ccrgst ?

2.- Are the tables master to child.... 1 Record in ccrtbl and many records in ccrgst ?

3.- How many fields are there in the 2 tables ?

4.- Both tables have an Index with the relation field ?

Answers to possible errors...

1.- Here is the most perfect relation... there must be no error and the query is very fast... if there is 1 to 1 relation

2.- Here you must thing backwards.... Select on the child table... the numbers of resulting rows must be the initial number of records in that table. So very fast indeed.... BUT. If you do it all the way around you may have a big resulting query, then a slow query result.

3.- If you have 50 fields on the tables, you must assume that you are going to get a 100 fields query. Then the idea is to reduce it to have only the required fields to work in the query. Also try to use alias.

Ex.
Select chi.code, chi.number, chi.ammount, mas.date, mas.client from child as chi left join master as mas on chi.CodeMas=mas.Code

4.- Best way of having fast and accurate results, the fields used to do the relation mus be and index too in both tables.

Hope it helps.

From Chile
Adolfo
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Lenovo Legion Y520, 16GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1050
User avatar
dutch
Posts: 1395
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to use JOIN command in MySql.LIB?

Post by dutch »

Dear Adolfo,

The problem is my knowledge. It works great after create an index.
1) yes, 1 to 1.
2) No, Master 1 to Child 1 record.
3) Around 140 coluums.
4) NO INDEX

I created an index in MySqlQueryBrowsers and try to open the sample program a again. It took 1-2 seconds only.

Code: Select all

CREATE INDEX ccrgst1 ON ccrgst (gst_intno)
Thank you so much for all.
Adolfo wrote:Dutch.. you must be more specific..

1.- Are the tables 1 to 1.... 1 Record in ccrtbl and 1 record in ccrgst ?

2.- Are the tables master to child.... 1 Record in ccrtbl and many records in ccrgst ?

3.- How many fields are there in the 2 tables ?

4.- Both tables have an Index with the relation field ?

Answers to possible errors...

1.- Here is the most perfect relation... there must be no error and the query is very fast... if there is 1 to 1 relation

2.- Here you must thing backwards.... Select on the child table... the numbers of resulting rows must be the initial number of records in that table. So very fast indeed.... BUT. If you do it all the way around you may have a big resulting query, then a slow query result.

3.- If you have 50 fields on the tables, you must assume that you are going to get a 100 fields query. Then the idea is to reduce it to have only the required fields to work in the query. Also try to use alias.

Ex.
Select chi.code, chi.number, chi.ammount, mas.date, mas.client from child as chi left join master as mas on chi.CodeMas=mas.Code

4.- Best way of having fast and accurate results, the fields used to do the relation mus be and index too in both tables.

Hope it helps.

From Chile
Adolfo
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
Adolfo
Posts: 815
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile
Contact:

Re: How to use JOIN command in MySql.LIB?*Understood/More Clear*

Post by Adolfo »

Great it helps...

Any other doubt do not hesitate... and contact me here... or to my private email.

Greetings
From Chile.
Adolfo
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Lenovo Legion Y520, 16GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1050
User avatar
dutch
Posts: 1395
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to use JOIN command in MySql.LIB?*Understood/More Clear*

Post by dutch »

Thank you so much for your kindness.
Adolfo wrote:Great it helps...

Any other doubt do not hesitate... and contact me here... or to my private email.

Greetings
From Chile.
Adolfo
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
Post Reply