Jump to content

to loop or not to loop?


Go to solution Solved by Barand,

Recommended Posts

20 minutes ago, Barand said:

I fell foul of that this morning. It worked fine yesterday when I posted the query but when I loaded some more data and ran it again after midnight I got nothing. The last date I had was 2025-01-26 so -7 DAY worked fine on the 2nd Feb but not on the 3rd.

On the subject of temporary tables, have a look at WITH RECURSIVE. There may be occasions when you want to list, say, total sales for each day last month and show a zero total for days with no sales. You can't just sum, grouping by the dates, as you won't get output if there is no data fora  date. You need a table containing all the dates in the month and use a left join. WITH RECURSIVE gives a great way of create such a temporary date table on the fly.

easy to forget, i guess. I'm used to working on my own projects on an up-to-date xampp installation. I just forgot that we have an outdated dump file. I suppose that it is simply a common mistake when focusing on the code.

I have found several resources on the recursive cte topic:

https://dev.mysql.com/doc/refman/8.4/en/with.html
https://www.mysqltutorial.org/mysql-basics/mysql-recursive-cte/
https://bobcares.com/blog/mysql-recursive-cte/
https://mariadb.com/kb/en/with/
https://mariadb.com/kb/en/recursive-common-table-expressions-overview/
https://matthewdaly.co.uk/blog/2022/12/18/two-techniques-for-handling-recursive-relationships-in-mysql/
 

I'm going to play with this concept to gain some experience as quickly as possible, although mastering the subject will cost some time. Very fascinating. I need to upgrade my knowledge of sql in the process of this forum.

Thanks for the tip, Barry. Now please spend some time relaxing. I have to log off now as my son has an appointment with a doctor. I will be back in a few hours, then i will continue upgrading my sql skills.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.