Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL virtual fields for duplicate results
    primarykey
    data
    text
    <p>I apologize in advance that I don't know the terminology of the tools I'm trying to use.</p> <p>I have a table of events with a startdate field (among others) and a related repeats table with a reference to the event id. The repeats table stores the days of the week on which the event repeats and whether it's monthly, weekly, etc. What I'm hoping to do is duplicate the repeating events within the SQL query so my final result will have the the same event in different places when ordered on start date, so I can limit the results for proper pagination.</p> <p>I'm looking at creating virtual tables and cloning tables documentation, but I'm having trouble applying the examples to my situation.</p> <p><strong>Update:</strong></p> <p>Hopefully I can elaborate on this.</p> <p>The basics of what I have now is <code>SELECT * FROM 'events' WHERE 'start_date' &gt;= TODAY() ORDER BY 'start_date LIMIT 20</code> which gets me every event from today on, but I'm paginating the results so only 20 are displayed at a time.</p> <p>What I would like to do is create a temporary 'virtual' table with the events which have an associated repeat entry, on which I will change the <code>start_date</code> based on the repeat information. So if it's a weekly repeat, this second table would be filled with identical events except that each <code>start_date</code> would be 7 days from the last. Then I could do a join on these two tables, limit those results to the 20 pagination limit I want, and have a query result with the events in the correct place and easy to perform pagination on.</p> <p>I understand that creating a function in mySQL might be on the right track as I imagine I would have to loop through some information for adding to dates. I only know the level of SQL one picks up by writing in PHP, so functions are a bit out of my scope, though it doesn't seem that it'll be too hard to pick up with a little reading. I'm more confused about how I would create a fake table, add entries to it in a loop and then use a join on it to merge it with the first query.</p> <p>I'm also beginning to wonder about the overhead for doing this in mySQL and, should I be successful in getting this to work, how I might cache these results, though it's only an afterthought right now.</p> <p>Thanks to those who are trying to help me, I'm having trouble getting this question into words for some reason.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload