I’ve tried working through some previous answers, but they aren’t making a lot of sense.
I have two tables, one of “groups” representing real-world groups of people, and one of “events” representing meetings of the group.
I’ve got a terribly simple query that selects the groups, to show them in a list on the website, and a separate query on the group profile page that lists their upcoming meetings, and I’m unsure what technique to use to add the “next meeting” to the list of groups, ideally it needs to be returned as another column in the MySQL query.
I’ve been fine with joins before, but limiting the number of joined results to one, per row in the first table, doesn’t seem to straightforward.
Any simple advice on what technique would work to show this?
Thanks!
Rough schema as follows;
CREATE TABLE `groups` (
`id` varchar(12) NOT NULL,
`title` varchar(30) NOT NULL,
PRIMARY KEY (`slug`)
)
CREATE TABLE `events` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`group` varchar(20) NOT NULL,
`title` varchar(50) NOT NULL,
`start` datetime NOT NULL,
`finish` datetime NOT NULL,
PRIMARY KEY (`id`)
)
The schema you present is NOT consistent AND you did not provide your queries…
To give some sort of answer I made the assumption that
groups.id = events.group.To show the next event you could do something similar to this: