So I’m building a website where basically users can write stories and each story can have multiple continuations, but I’m trying to figure out how to query my database, so that I can return the first story and the continuations associated with that story, without getting repeated entries, which i would get if I’m just writing a join statement like so:
SELECT idStories,
Stories.Title,
Stories.Num_parts,
Stories.Story,
Stories.Date_poste,
idStory_continue,
Story_continue.Users_idUsers,
Story_continue.Title,
Story_continue.Story,
Story_continue.Date_posted,
Story_continue.Part_num
FROM Stories s
LEFT JOIN Story_continue sc ON sc.Stories_idStories = s.idStories
so my question is what is an efficent way of returning this type of query without getting multiple versions of the original story. for instance when I query this I will get all of the original stories, and I will get the continuations, but it repeats the original story if there are multiple continuations to each story. and if you can’t make a query that provides information in this way, how would you go about solving this in php?
You can try a GROUP BY clause, but if you want all the story_continue data, you will need to do a GROUP_CONCAT which can get messy.
I find it easier to split the query up like this. Usually it’s faster than a JOIN/GROUP BY anyways.