Questions around some SQL queries


Amin Mousavi
Hi David, I have got stock in optimising my query somewhere I think you could advise. I am trying to run the below query on the API you have provided for AB Database example: I use Database::getResults in the API to run the SELECT part that works fine, but I had not been able to run the CREATE VIEW as of yet. I tried and a few other pdo functions to execute the CREATE VIEW but had not luck. I appreciate if you advise. Regards,

decsoft

Hello Amin,

If I am not wrong, to create the VIEW you must use the "Database::exec()" method. So the only thing that I see rare is that if you use "Database::beginTransaction"()", after execute the query, you must execute "Database::commit()". Maybe you no need to use the "begin transaction" at all?

Can this help you in some manner?



Amin Mousavi
Hi David, During the debugging I figured that Was infact working correctly, and my view was created, the reason I get the errors is that I am trying to replicate "WITH" in MySQL and still have no luck. Thanks a million

decsoft

Hello Amin,

Then I am not sure if can understand. First of all, probably you want to create the view over and over again: once you create the view (for example with a database manager like PhpMyAdmin), what you must to do is to execute the appropriate SQL query. You talk about errors, Amin, but can you please refer that errors here?



Amin Mousavi
Thanks a lot David for always going the extra mile, I did not expect you to look into that because it is totally irrelevant to AB and the APIs I got from it. But any how to clear things up. I am running a query like below: Because both sides of JOIN are running the same query (SELECT * FROM T1) it will be more efficient if we can buffer it somewhere first time it is run and then reuse it the second time. This in a simplified example and when the reused query is something with a few joins and subqueries and data has millions of records it will make a measurable difference. In SQLSERVER and ORACLE this issue can be taking care of by TEMPORARY tables and/or WITH but MySQL temporary tables does not help with this. WITH is available in MySQL 8 apparently but my server's SQL version is 5.6 and does not support WITH so I am stuck doing my best to replicate these using views, memory engines and technically anything that has the ability to speed up my query in a similar fashion. Don't worry about it though, I will find a way for it ;)

decsoft

Hello Amin,

I am not an expert in SQL, so, I am not sure if can help you in the best way, but at least I can always try it. :-)


Todo el mundo puede leer el foro de soporte de DecSoft para aprender del mismo, sin embargo, sólo los clientes de DecSoft pueden abrir nuevos hilos. Compre una o más licencias de productos de DecSoft y obtendrá este y otros beneficios.

Este sitio utiliza "cookies" útiles para almacenar sus preferencias.

Bien. Ocultar esta nota. Obtener más información.