jodunno Posted Monday at 12:00 PM Author Share Posted Monday at 12:00 PM 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.htmlhttps://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. Quote Link to comment https://forums.phpfreaks.com/topic/326676-to-loop-or-not-to-loop/page/2/#findComment-1648962 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.