Hello everyone, I need your help.
I have five tables in my db mysql: tbl_A, tbl_b, tbl_C, tbl_D and tbl_E and I execute this four query:
SELECT COUNT(idDTES) AS stridDTES
, SUM(CL_BT_DIS) AS strCL_BT_DIS
, SUM(AV) AS strAV
, COUNT(SC) AS strL
, COUNT(idDTES) - COUNT(SC) AS strB
GROUP BY DATE_E
SELECT SUM(Rif_AV) AS strRif_AV
, SUM(Rif_n_CL) AS strRif_n_CL
SELECT SUM(tbl_C.cl_BT) AS strCl_BT
, COUNT(tbl_D.EVENT) AS strEVENT
INNER JOIN tbl_D ON tbl_D.LINE = tbl_C.COD_LINE
GROUP BY DATE_E
SELECT SUM(N_S_TR) AS strNSTR FROM tbl_E GROUP BY DATE_E
There is possible to have same output with only query combining the four queries?
Any help would be very much appreciated and many thanks to any who can help me.
Thanks in advance.
Many thanks for your help, I have change method.
You're grouping by DATA_E, but that field isn't in the select. There isn't any field in the select, just sums and counts. So how many rows does this query return?
And how do you know what each row contains if you don't select some identifying field as well (for example DATA_E)?
Many thanks x your help.
I have JOIN queries 1 and 2 and new query working, but I don't see for queries 3 and 4...:
COUNT(A.idDTES) AS stridDTES
, SUM(A.CL_BT_DIS) AS strCL_BT_DIS
, SUM(A.AV) AS strAV
, COUNT(A.SC) AS strL
, COUNT(A.idDTES) - COUNT(A.SC) AS strB
, SUM(CA.Rif_AV) AS strRif_AV
, SUM(CA.Rif_n_CL) AS strRif_n_CL
tbl_A A INNER JOIN tbl_B CA ON A.idDTES = CA.DM
GROUP BY DATA_E
That's not a UNION, that's a JOIN
If you want to union theese results, you should change your selected columns for all queries so their count will be the same (if you select 3 columns from first table, you should select 3 from second and third as well)