query working online but not on local machine





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















The Goal of my query is to identify all the suppliers with due invoices for this week. So the goal is just to have one entry per supplier, identifying the ones that should be showed this week.



SO my big question is why a query works online but not on local machine?



To get that i used the group by statement ant it was working so far! Now that i have a copy of what was online on my local server it stoped working as it should.



I have this query running online and everything works great:



$query_facturas_group = "SELECT TbFacturas.PkFacturas, TbFacturas.FkFornecedor, TbFacturas.FacturaData, TbFacturas.FacturaValor, TbFacturas.FacturaNumero, TbFacturas.FacturaEstado, TbFacturas.FacturaDataPagamento, Fornecedores.PkFornecedor, Fornecedores.NomeFornecedor, Fornecedores.EmailFornecedor 
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
WHERE TbFacturas.FacturaDataPagamento<'$pay_day' AND TbFacturas.FacturaEstado='0' AND TbFacturas.FacturaTrash='0'
GROUP BY TbFacturas.FkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";


The problem is that when I try to run it locally (to make some changes and upgrade it) it stopped working (no results).



Also, when I run it straight in the MySQL console, it works great...



I started removing parts of the code and it works (but not giving me the result I'm looking for...)



As soon as I remove the GROUP BY statement it starts working - but not the expected result...



I tried using it with SELECT DISTINCT but with no success as it still shows Repeat Suppliers Name (Fornecedores.NomeFornecedor field).



Any guess??
UPDATE:
I noticed that there is another query in my project that does not work with GROUP BY




  • PRINT SCREEN FROM THE RESULT IN HTML:


enter image description here




  • PRINT SCREEN RESULT FROM CONSOLE


enter image description here










share|improve this question




















  • 2





    Is there any error or your expected result is not come?

    – Sadikhasan
    Nov 16 '18 at 12:00








  • 1





    @sadikhasan just no results... When i remove the group by statement it starts working... I've tried looking at it 100o times and I didn't find the error. The strangest part is that it works in sql console...

    – castro_pereira
    Nov 16 '18 at 12:02






  • 1





    can you post more code and the expected results and the wrong results you getting

    – Masivuye Cokile
    Nov 16 '18 at 12:03






  • 2





    Try to import your live database in local and then test it because your locally data and live data may be mismatched.

    – Sadikhasan
    Nov 16 '18 at 12:03






  • 1





    "i have this query running online and everything works great:" i don't really believe that it 's can't be working great online because you are misusing MySQL extended GROUP BY feature which can cause invalid results this is a very common mistake/error on MySQL psce.com/en/blog/2012/05/15/… .. Besides i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

    – Raymond Nijland
    Nov 16 '18 at 12:08




















0















The Goal of my query is to identify all the suppliers with due invoices for this week. So the goal is just to have one entry per supplier, identifying the ones that should be showed this week.



SO my big question is why a query works online but not on local machine?



To get that i used the group by statement ant it was working so far! Now that i have a copy of what was online on my local server it stoped working as it should.



I have this query running online and everything works great:



$query_facturas_group = "SELECT TbFacturas.PkFacturas, TbFacturas.FkFornecedor, TbFacturas.FacturaData, TbFacturas.FacturaValor, TbFacturas.FacturaNumero, TbFacturas.FacturaEstado, TbFacturas.FacturaDataPagamento, Fornecedores.PkFornecedor, Fornecedores.NomeFornecedor, Fornecedores.EmailFornecedor 
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
WHERE TbFacturas.FacturaDataPagamento<'$pay_day' AND TbFacturas.FacturaEstado='0' AND TbFacturas.FacturaTrash='0'
GROUP BY TbFacturas.FkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";


The problem is that when I try to run it locally (to make some changes and upgrade it) it stopped working (no results).



Also, when I run it straight in the MySQL console, it works great...



I started removing parts of the code and it works (but not giving me the result I'm looking for...)



As soon as I remove the GROUP BY statement it starts working - but not the expected result...



I tried using it with SELECT DISTINCT but with no success as it still shows Repeat Suppliers Name (Fornecedores.NomeFornecedor field).



Any guess??
UPDATE:
I noticed that there is another query in my project that does not work with GROUP BY




  • PRINT SCREEN FROM THE RESULT IN HTML:


enter image description here




  • PRINT SCREEN RESULT FROM CONSOLE


enter image description here










share|improve this question




















  • 2





    Is there any error or your expected result is not come?

    – Sadikhasan
    Nov 16 '18 at 12:00








  • 1





    @sadikhasan just no results... When i remove the group by statement it starts working... I've tried looking at it 100o times and I didn't find the error. The strangest part is that it works in sql console...

    – castro_pereira
    Nov 16 '18 at 12:02






  • 1





    can you post more code and the expected results and the wrong results you getting

    – Masivuye Cokile
    Nov 16 '18 at 12:03






  • 2





    Try to import your live database in local and then test it because your locally data and live data may be mismatched.

    – Sadikhasan
    Nov 16 '18 at 12:03






  • 1





    "i have this query running online and everything works great:" i don't really believe that it 's can't be working great online because you are misusing MySQL extended GROUP BY feature which can cause invalid results this is a very common mistake/error on MySQL psce.com/en/blog/2012/05/15/… .. Besides i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

    – Raymond Nijland
    Nov 16 '18 at 12:08
















0












0








0








The Goal of my query is to identify all the suppliers with due invoices for this week. So the goal is just to have one entry per supplier, identifying the ones that should be showed this week.



SO my big question is why a query works online but not on local machine?



To get that i used the group by statement ant it was working so far! Now that i have a copy of what was online on my local server it stoped working as it should.



I have this query running online and everything works great:



$query_facturas_group = "SELECT TbFacturas.PkFacturas, TbFacturas.FkFornecedor, TbFacturas.FacturaData, TbFacturas.FacturaValor, TbFacturas.FacturaNumero, TbFacturas.FacturaEstado, TbFacturas.FacturaDataPagamento, Fornecedores.PkFornecedor, Fornecedores.NomeFornecedor, Fornecedores.EmailFornecedor 
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
WHERE TbFacturas.FacturaDataPagamento<'$pay_day' AND TbFacturas.FacturaEstado='0' AND TbFacturas.FacturaTrash='0'
GROUP BY TbFacturas.FkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";


The problem is that when I try to run it locally (to make some changes and upgrade it) it stopped working (no results).



Also, when I run it straight in the MySQL console, it works great...



I started removing parts of the code and it works (but not giving me the result I'm looking for...)



As soon as I remove the GROUP BY statement it starts working - but not the expected result...



I tried using it with SELECT DISTINCT but with no success as it still shows Repeat Suppliers Name (Fornecedores.NomeFornecedor field).



Any guess??
UPDATE:
I noticed that there is another query in my project that does not work with GROUP BY




  • PRINT SCREEN FROM THE RESULT IN HTML:


enter image description here




  • PRINT SCREEN RESULT FROM CONSOLE


enter image description here










share|improve this question
















The Goal of my query is to identify all the suppliers with due invoices for this week. So the goal is just to have one entry per supplier, identifying the ones that should be showed this week.



SO my big question is why a query works online but not on local machine?



To get that i used the group by statement ant it was working so far! Now that i have a copy of what was online on my local server it stoped working as it should.



I have this query running online and everything works great:



$query_facturas_group = "SELECT TbFacturas.PkFacturas, TbFacturas.FkFornecedor, TbFacturas.FacturaData, TbFacturas.FacturaValor, TbFacturas.FacturaNumero, TbFacturas.FacturaEstado, TbFacturas.FacturaDataPagamento, Fornecedores.PkFornecedor, Fornecedores.NomeFornecedor, Fornecedores.EmailFornecedor 
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
WHERE TbFacturas.FacturaDataPagamento<'$pay_day' AND TbFacturas.FacturaEstado='0' AND TbFacturas.FacturaTrash='0'
GROUP BY TbFacturas.FkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";


The problem is that when I try to run it locally (to make some changes and upgrade it) it stopped working (no results).



Also, when I run it straight in the MySQL console, it works great...



I started removing parts of the code and it works (but not giving me the result I'm looking for...)



As soon as I remove the GROUP BY statement it starts working - but not the expected result...



I tried using it with SELECT DISTINCT but with no success as it still shows Repeat Suppliers Name (Fornecedores.NomeFornecedor field).



Any guess??
UPDATE:
I noticed that there is another query in my project that does not work with GROUP BY




  • PRINT SCREEN FROM THE RESULT IN HTML:


enter image description here




  • PRINT SCREEN RESULT FROM CONSOLE


enter image description here







php mysql mysqli group-by






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 12:27







castro_pereira

















asked Nov 16 '18 at 11:56









castro_pereiracastro_pereira

348




348








  • 2





    Is there any error or your expected result is not come?

    – Sadikhasan
    Nov 16 '18 at 12:00








  • 1





    @sadikhasan just no results... When i remove the group by statement it starts working... I've tried looking at it 100o times and I didn't find the error. The strangest part is that it works in sql console...

    – castro_pereira
    Nov 16 '18 at 12:02






  • 1





    can you post more code and the expected results and the wrong results you getting

    – Masivuye Cokile
    Nov 16 '18 at 12:03






  • 2





    Try to import your live database in local and then test it because your locally data and live data may be mismatched.

    – Sadikhasan
    Nov 16 '18 at 12:03






  • 1





    "i have this query running online and everything works great:" i don't really believe that it 's can't be working great online because you are misusing MySQL extended GROUP BY feature which can cause invalid results this is a very common mistake/error on MySQL psce.com/en/blog/2012/05/15/… .. Besides i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

    – Raymond Nijland
    Nov 16 '18 at 12:08
















  • 2





    Is there any error or your expected result is not come?

    – Sadikhasan
    Nov 16 '18 at 12:00








  • 1





    @sadikhasan just no results... When i remove the group by statement it starts working... I've tried looking at it 100o times and I didn't find the error. The strangest part is that it works in sql console...

    – castro_pereira
    Nov 16 '18 at 12:02






  • 1





    can you post more code and the expected results and the wrong results you getting

    – Masivuye Cokile
    Nov 16 '18 at 12:03






  • 2





    Try to import your live database in local and then test it because your locally data and live data may be mismatched.

    – Sadikhasan
    Nov 16 '18 at 12:03






  • 1





    "i have this query running online and everything works great:" i don't really believe that it 's can't be working great online because you are misusing MySQL extended GROUP BY feature which can cause invalid results this is a very common mistake/error on MySQL psce.com/en/blog/2012/05/15/… .. Besides i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

    – Raymond Nijland
    Nov 16 '18 at 12:08










2




2





Is there any error or your expected result is not come?

– Sadikhasan
Nov 16 '18 at 12:00







Is there any error or your expected result is not come?

– Sadikhasan
Nov 16 '18 at 12:00






1




1





@sadikhasan just no results... When i remove the group by statement it starts working... I've tried looking at it 100o times and I didn't find the error. The strangest part is that it works in sql console...

– castro_pereira
Nov 16 '18 at 12:02





@sadikhasan just no results... When i remove the group by statement it starts working... I've tried looking at it 100o times and I didn't find the error. The strangest part is that it works in sql console...

– castro_pereira
Nov 16 '18 at 12:02




1




1





can you post more code and the expected results and the wrong results you getting

– Masivuye Cokile
Nov 16 '18 at 12:03





can you post more code and the expected results and the wrong results you getting

– Masivuye Cokile
Nov 16 '18 at 12:03




2




2





Try to import your live database in local and then test it because your locally data and live data may be mismatched.

– Sadikhasan
Nov 16 '18 at 12:03





Try to import your live database in local and then test it because your locally data and live data may be mismatched.

– Sadikhasan
Nov 16 '18 at 12:03




1




1





"i have this query running online and everything works great:" i don't really believe that it 's can't be working great online because you are misusing MySQL extended GROUP BY feature which can cause invalid results this is a very common mistake/error on MySQL psce.com/en/blog/2012/05/15/… .. Besides i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

– Raymond Nijland
Nov 16 '18 at 12:08







"i have this query running online and everything works great:" i don't really believe that it 's can't be working great online because you are misusing MySQL extended GROUP BY feature which can cause invalid results this is a very common mistake/error on MySQL psce.com/en/blog/2012/05/15/… .. Besides i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

– Raymond Nijland
Nov 16 '18 at 12:08














1 Answer
1






active

oldest

votes


















1














Could be you are using two different version of mysql one oldest than 5.6 on server and one more recent locally .. the group by behaviour is changed starting fro d.6 and do the fact
you are using group by without aggregation function

this is deprecated in SQL not allowed in most recent version on mysql and for the oldest versione the result for column values not involved in group is unpredictable ..



so if you just want distinct result the you could use DISTINCT avoiding group by



$query_facturas_group = "SELECT DISTINCT TbFacturas.PkFacturas
, TbFacturas.FkFornecedor
, TbFacturas.FacturaData
, TbFacturas.FacturaValor
, TbFacturas.FacturaNumero
, TbFacturas.FacturaEstado
, TbFacturas.FacturaDataPagamento
, Fornecedores.PkFornecedor
, Fornecedores.NomeFornecedor
, Fornecedores.EmailFornecedor
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";


if you just want to reduce the number of rows the you should use aggreagtion function and group eg min() or max()



$query_facturas_group = "SELECT 
min(TbFacturas.PkFacturas)
, TbFacturas.FkFornecedor
, min(TbFacturas.FacturaData)
, min(TbFacturas.FacturaValor)
, min(TbFacturas.FacturaNumero)
, min(TbFacturas.FacturaEstado)
, min(TbFacturas.FacturaDataPagamento)
, min(Fornecedores.PkFornecedor)
, min(Fornecedores.NomeFornecedor)
, min(Fornecedores.EmailFornecedor )
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
WHERE TbFacturas.FacturaDataPagamento<'$pay_day' AND TbFacturas.FacturaEstado='0' AND TbFacturas.FacturaTrash='0'
GROUP BY TbFacturas.FkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";





share|improve this answer
























  • It makes sense! I'll try what you are saying, but the awkward part of it is that the same query works when in the Sql console, just doesn't work via PHP...

    – castro_pereira
    Nov 16 '18 at 14:46











  • it works! but i still have no clue why it work on the console but not via php... thank you for your time!

    – castro_pereira
    Nov 16 '18 at 15:05













  • In sqlconsole youn have a warning ?? ..the sqlconsole in which db version work?

    – scaisEdge
    Nov 16 '18 at 15:38











  • LOCAL SERVER: innodb_version 5.7.23 protocol_version 10 slave_type_conversions tls_version TLSv1,TLSv1.1 version 5.7.23 version_comment MySQL Community Server (GPL) version_compile_machine x86_64 version_compile_os osx10.9 ONLINE: innodb_version 5.6.39-83.1 protocol_version 10 slave_type_conversions version 10.1.36-MariaDB-cll-lve version_comment MariaDB Server version_compile_machine x86_64 version_compile_os Linux version_malloc_library system jemalloc version_ssl_library OpenSSL 1.0.2k-fips 26 Jan 2017 wsrep_patch_version wsrep_25.23

    – castro_pereira
    Nov 16 '18 at 15:42













  • Cold be in online server you have a sql_mode setting different respect the local . You could check the sql_mode .using . SELECT @@GLOBAL.sql_mode;

    – scaisEdge
    Nov 16 '18 at 16:00












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337426%2fquery-working-online-but-not-on-local-machine%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Could be you are using two different version of mysql one oldest than 5.6 on server and one more recent locally .. the group by behaviour is changed starting fro d.6 and do the fact
you are using group by without aggregation function

this is deprecated in SQL not allowed in most recent version on mysql and for the oldest versione the result for column values not involved in group is unpredictable ..



so if you just want distinct result the you could use DISTINCT avoiding group by



$query_facturas_group = "SELECT DISTINCT TbFacturas.PkFacturas
, TbFacturas.FkFornecedor
, TbFacturas.FacturaData
, TbFacturas.FacturaValor
, TbFacturas.FacturaNumero
, TbFacturas.FacturaEstado
, TbFacturas.FacturaDataPagamento
, Fornecedores.PkFornecedor
, Fornecedores.NomeFornecedor
, Fornecedores.EmailFornecedor
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";


if you just want to reduce the number of rows the you should use aggreagtion function and group eg min() or max()



$query_facturas_group = "SELECT 
min(TbFacturas.PkFacturas)
, TbFacturas.FkFornecedor
, min(TbFacturas.FacturaData)
, min(TbFacturas.FacturaValor)
, min(TbFacturas.FacturaNumero)
, min(TbFacturas.FacturaEstado)
, min(TbFacturas.FacturaDataPagamento)
, min(Fornecedores.PkFornecedor)
, min(Fornecedores.NomeFornecedor)
, min(Fornecedores.EmailFornecedor )
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
WHERE TbFacturas.FacturaDataPagamento<'$pay_day' AND TbFacturas.FacturaEstado='0' AND TbFacturas.FacturaTrash='0'
GROUP BY TbFacturas.FkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";





share|improve this answer
























  • It makes sense! I'll try what you are saying, but the awkward part of it is that the same query works when in the Sql console, just doesn't work via PHP...

    – castro_pereira
    Nov 16 '18 at 14:46











  • it works! but i still have no clue why it work on the console but not via php... thank you for your time!

    – castro_pereira
    Nov 16 '18 at 15:05













  • In sqlconsole youn have a warning ?? ..the sqlconsole in which db version work?

    – scaisEdge
    Nov 16 '18 at 15:38











  • LOCAL SERVER: innodb_version 5.7.23 protocol_version 10 slave_type_conversions tls_version TLSv1,TLSv1.1 version 5.7.23 version_comment MySQL Community Server (GPL) version_compile_machine x86_64 version_compile_os osx10.9 ONLINE: innodb_version 5.6.39-83.1 protocol_version 10 slave_type_conversions version 10.1.36-MariaDB-cll-lve version_comment MariaDB Server version_compile_machine x86_64 version_compile_os Linux version_malloc_library system jemalloc version_ssl_library OpenSSL 1.0.2k-fips 26 Jan 2017 wsrep_patch_version wsrep_25.23

    – castro_pereira
    Nov 16 '18 at 15:42













  • Cold be in online server you have a sql_mode setting different respect the local . You could check the sql_mode .using . SELECT @@GLOBAL.sql_mode;

    – scaisEdge
    Nov 16 '18 at 16:00
















1














Could be you are using two different version of mysql one oldest than 5.6 on server and one more recent locally .. the group by behaviour is changed starting fro d.6 and do the fact
you are using group by without aggregation function

this is deprecated in SQL not allowed in most recent version on mysql and for the oldest versione the result for column values not involved in group is unpredictable ..



so if you just want distinct result the you could use DISTINCT avoiding group by



$query_facturas_group = "SELECT DISTINCT TbFacturas.PkFacturas
, TbFacturas.FkFornecedor
, TbFacturas.FacturaData
, TbFacturas.FacturaValor
, TbFacturas.FacturaNumero
, TbFacturas.FacturaEstado
, TbFacturas.FacturaDataPagamento
, Fornecedores.PkFornecedor
, Fornecedores.NomeFornecedor
, Fornecedores.EmailFornecedor
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";


if you just want to reduce the number of rows the you should use aggreagtion function and group eg min() or max()



$query_facturas_group = "SELECT 
min(TbFacturas.PkFacturas)
, TbFacturas.FkFornecedor
, min(TbFacturas.FacturaData)
, min(TbFacturas.FacturaValor)
, min(TbFacturas.FacturaNumero)
, min(TbFacturas.FacturaEstado)
, min(TbFacturas.FacturaDataPagamento)
, min(Fornecedores.PkFornecedor)
, min(Fornecedores.NomeFornecedor)
, min(Fornecedores.EmailFornecedor )
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
WHERE TbFacturas.FacturaDataPagamento<'$pay_day' AND TbFacturas.FacturaEstado='0' AND TbFacturas.FacturaTrash='0'
GROUP BY TbFacturas.FkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";





share|improve this answer
























  • It makes sense! I'll try what you are saying, but the awkward part of it is that the same query works when in the Sql console, just doesn't work via PHP...

    – castro_pereira
    Nov 16 '18 at 14:46











  • it works! but i still have no clue why it work on the console but not via php... thank you for your time!

    – castro_pereira
    Nov 16 '18 at 15:05













  • In sqlconsole youn have a warning ?? ..the sqlconsole in which db version work?

    – scaisEdge
    Nov 16 '18 at 15:38











  • LOCAL SERVER: innodb_version 5.7.23 protocol_version 10 slave_type_conversions tls_version TLSv1,TLSv1.1 version 5.7.23 version_comment MySQL Community Server (GPL) version_compile_machine x86_64 version_compile_os osx10.9 ONLINE: innodb_version 5.6.39-83.1 protocol_version 10 slave_type_conversions version 10.1.36-MariaDB-cll-lve version_comment MariaDB Server version_compile_machine x86_64 version_compile_os Linux version_malloc_library system jemalloc version_ssl_library OpenSSL 1.0.2k-fips 26 Jan 2017 wsrep_patch_version wsrep_25.23

    – castro_pereira
    Nov 16 '18 at 15:42













  • Cold be in online server you have a sql_mode setting different respect the local . You could check the sql_mode .using . SELECT @@GLOBAL.sql_mode;

    – scaisEdge
    Nov 16 '18 at 16:00














1












1








1







Could be you are using two different version of mysql one oldest than 5.6 on server and one more recent locally .. the group by behaviour is changed starting fro d.6 and do the fact
you are using group by without aggregation function

this is deprecated in SQL not allowed in most recent version on mysql and for the oldest versione the result for column values not involved in group is unpredictable ..



so if you just want distinct result the you could use DISTINCT avoiding group by



$query_facturas_group = "SELECT DISTINCT TbFacturas.PkFacturas
, TbFacturas.FkFornecedor
, TbFacturas.FacturaData
, TbFacturas.FacturaValor
, TbFacturas.FacturaNumero
, TbFacturas.FacturaEstado
, TbFacturas.FacturaDataPagamento
, Fornecedores.PkFornecedor
, Fornecedores.NomeFornecedor
, Fornecedores.EmailFornecedor
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";


if you just want to reduce the number of rows the you should use aggreagtion function and group eg min() or max()



$query_facturas_group = "SELECT 
min(TbFacturas.PkFacturas)
, TbFacturas.FkFornecedor
, min(TbFacturas.FacturaData)
, min(TbFacturas.FacturaValor)
, min(TbFacturas.FacturaNumero)
, min(TbFacturas.FacturaEstado)
, min(TbFacturas.FacturaDataPagamento)
, min(Fornecedores.PkFornecedor)
, min(Fornecedores.NomeFornecedor)
, min(Fornecedores.EmailFornecedor )
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
WHERE TbFacturas.FacturaDataPagamento<'$pay_day' AND TbFacturas.FacturaEstado='0' AND TbFacturas.FacturaTrash='0'
GROUP BY TbFacturas.FkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";





share|improve this answer













Could be you are using two different version of mysql one oldest than 5.6 on server and one more recent locally .. the group by behaviour is changed starting fro d.6 and do the fact
you are using group by without aggregation function

this is deprecated in SQL not allowed in most recent version on mysql and for the oldest versione the result for column values not involved in group is unpredictable ..



so if you just want distinct result the you could use DISTINCT avoiding group by



$query_facturas_group = "SELECT DISTINCT TbFacturas.PkFacturas
, TbFacturas.FkFornecedor
, TbFacturas.FacturaData
, TbFacturas.FacturaValor
, TbFacturas.FacturaNumero
, TbFacturas.FacturaEstado
, TbFacturas.FacturaDataPagamento
, Fornecedores.PkFornecedor
, Fornecedores.NomeFornecedor
, Fornecedores.EmailFornecedor
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";


if you just want to reduce the number of rows the you should use aggreagtion function and group eg min() or max()



$query_facturas_group = "SELECT 
min(TbFacturas.PkFacturas)
, TbFacturas.FkFornecedor
, min(TbFacturas.FacturaData)
, min(TbFacturas.FacturaValor)
, min(TbFacturas.FacturaNumero)
, min(TbFacturas.FacturaEstado)
, min(TbFacturas.FacturaDataPagamento)
, min(Fornecedores.PkFornecedor)
, min(Fornecedores.NomeFornecedor)
, min(Fornecedores.EmailFornecedor )
FROM TbFacturas
LEFT JOIN Fornecedores ON TbFacturas.FkFornecedor=Fornecedores.PkFornecedor
WHERE TbFacturas.FacturaDataPagamento<'$pay_day' AND TbFacturas.FacturaEstado='0' AND TbFacturas.FacturaTrash='0'
GROUP BY TbFacturas.FkFornecedor
ORDER BY Fornecedores.NomeFornecedor ASC";






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 13:02









scaisEdgescaisEdge

97.4k105272




97.4k105272













  • It makes sense! I'll try what you are saying, but the awkward part of it is that the same query works when in the Sql console, just doesn't work via PHP...

    – castro_pereira
    Nov 16 '18 at 14:46











  • it works! but i still have no clue why it work on the console but not via php... thank you for your time!

    – castro_pereira
    Nov 16 '18 at 15:05













  • In sqlconsole youn have a warning ?? ..the sqlconsole in which db version work?

    – scaisEdge
    Nov 16 '18 at 15:38











  • LOCAL SERVER: innodb_version 5.7.23 protocol_version 10 slave_type_conversions tls_version TLSv1,TLSv1.1 version 5.7.23 version_comment MySQL Community Server (GPL) version_compile_machine x86_64 version_compile_os osx10.9 ONLINE: innodb_version 5.6.39-83.1 protocol_version 10 slave_type_conversions version 10.1.36-MariaDB-cll-lve version_comment MariaDB Server version_compile_machine x86_64 version_compile_os Linux version_malloc_library system jemalloc version_ssl_library OpenSSL 1.0.2k-fips 26 Jan 2017 wsrep_patch_version wsrep_25.23

    – castro_pereira
    Nov 16 '18 at 15:42













  • Cold be in online server you have a sql_mode setting different respect the local . You could check the sql_mode .using . SELECT @@GLOBAL.sql_mode;

    – scaisEdge
    Nov 16 '18 at 16:00



















  • It makes sense! I'll try what you are saying, but the awkward part of it is that the same query works when in the Sql console, just doesn't work via PHP...

    – castro_pereira
    Nov 16 '18 at 14:46











  • it works! but i still have no clue why it work on the console but not via php... thank you for your time!

    – castro_pereira
    Nov 16 '18 at 15:05













  • In sqlconsole youn have a warning ?? ..the sqlconsole in which db version work?

    – scaisEdge
    Nov 16 '18 at 15:38











  • LOCAL SERVER: innodb_version 5.7.23 protocol_version 10 slave_type_conversions tls_version TLSv1,TLSv1.1 version 5.7.23 version_comment MySQL Community Server (GPL) version_compile_machine x86_64 version_compile_os osx10.9 ONLINE: innodb_version 5.6.39-83.1 protocol_version 10 slave_type_conversions version 10.1.36-MariaDB-cll-lve version_comment MariaDB Server version_compile_machine x86_64 version_compile_os Linux version_malloc_library system jemalloc version_ssl_library OpenSSL 1.0.2k-fips 26 Jan 2017 wsrep_patch_version wsrep_25.23

    – castro_pereira
    Nov 16 '18 at 15:42













  • Cold be in online server you have a sql_mode setting different respect the local . You could check the sql_mode .using . SELECT @@GLOBAL.sql_mode;

    – scaisEdge
    Nov 16 '18 at 16:00

















It makes sense! I'll try what you are saying, but the awkward part of it is that the same query works when in the Sql console, just doesn't work via PHP...

– castro_pereira
Nov 16 '18 at 14:46





It makes sense! I'll try what you are saying, but the awkward part of it is that the same query works when in the Sql console, just doesn't work via PHP...

– castro_pereira
Nov 16 '18 at 14:46













it works! but i still have no clue why it work on the console but not via php... thank you for your time!

– castro_pereira
Nov 16 '18 at 15:05







it works! but i still have no clue why it work on the console but not via php... thank you for your time!

– castro_pereira
Nov 16 '18 at 15:05















In sqlconsole youn have a warning ?? ..the sqlconsole in which db version work?

– scaisEdge
Nov 16 '18 at 15:38





In sqlconsole youn have a warning ?? ..the sqlconsole in which db version work?

– scaisEdge
Nov 16 '18 at 15:38













LOCAL SERVER: innodb_version 5.7.23 protocol_version 10 slave_type_conversions tls_version TLSv1,TLSv1.1 version 5.7.23 version_comment MySQL Community Server (GPL) version_compile_machine x86_64 version_compile_os osx10.9 ONLINE: innodb_version 5.6.39-83.1 protocol_version 10 slave_type_conversions version 10.1.36-MariaDB-cll-lve version_comment MariaDB Server version_compile_machine x86_64 version_compile_os Linux version_malloc_library system jemalloc version_ssl_library OpenSSL 1.0.2k-fips 26 Jan 2017 wsrep_patch_version wsrep_25.23

– castro_pereira
Nov 16 '18 at 15:42







LOCAL SERVER: innodb_version 5.7.23 protocol_version 10 slave_type_conversions tls_version TLSv1,TLSv1.1 version 5.7.23 version_comment MySQL Community Server (GPL) version_compile_machine x86_64 version_compile_os osx10.9 ONLINE: innodb_version 5.6.39-83.1 protocol_version 10 slave_type_conversions version 10.1.36-MariaDB-cll-lve version_comment MariaDB Server version_compile_machine x86_64 version_compile_os Linux version_malloc_library system jemalloc version_ssl_library OpenSSL 1.0.2k-fips 26 Jan 2017 wsrep_patch_version wsrep_25.23

– castro_pereira
Nov 16 '18 at 15:42















Cold be in online server you have a sql_mode setting different respect the local . You could check the sql_mode .using . SELECT @@GLOBAL.sql_mode;

– scaisEdge
Nov 16 '18 at 16:00





Cold be in online server you have a sql_mode setting different respect the local . You could check the sql_mode .using . SELECT @@GLOBAL.sql_mode;

– scaisEdge
Nov 16 '18 at 16:00




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337426%2fquery-working-online-but-not-on-local-machine%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues