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

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

Postby dutch » Tue Jun 23, 2015 6:20 am

I try with JOIN command but it doesn't successful. How can I use it?
Code: Select all  Expand view
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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

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

Postby AntoninoP » Tue Jun 23, 2015 7:29 am

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/33052/Visual-Representation-of-SQL-Joins
Hope I am helping,
Regards,
Antonino Perricone
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

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

Postby Enrico Maria Giordano » Tue Jun 23, 2015 8:35 am

Dutch,

dutch wrote:
Code: Select all  Expand view
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
Enrico Maria Giordano
 
Posts: 8378
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby dutch » Tue Jun 23, 2015 9:45 am

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
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

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

Postby Adolfo » Tue Jun 23, 2015 11:57 am

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
----------
Asus TUF F15, 32GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1650
User avatar
Adolfo
 
Posts: 846
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

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

Postby dutch » Wed Jun 24, 2015 2:46 am

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  Expand view
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
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

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

Postby Adolfo » Wed Jun 24, 2015 1:20 pm

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
----------
Asus TUF F15, 32GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1650
User avatar
Adolfo
 
Posts: 846
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

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

Postby dutch » Wed Jun 24, 2015 11:08 pm

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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 23 guests