Select Earliest Related Row

Don Wieland <[email protected]>
Newsgroups gmane.comp.db.mysql.general
Message-ID <[email protected]>
I have a two tables where I am adding CLASSES and CLASS_DATES for people to register for.

Table Name = tl_items (Parent)
item_id
class_name


table_name = tl_items_classes (Children)
class_date_id
item_id
cl_date

“tl_items" will have 0 to Many “tl_items_classes" using the “item_id” as the KEY field.

I am compiling a SELECT query to search the dates of the classes (tl_items_classes rows), but I need to these two things:

1) Only show the EARLIEST “cl_date" in my returned list (i.e... if a class has dates for Jan 2,3,4,5,6 2016, only show Jan 2’s row)

2) In that displayed EARLIEST Class Date row, have a column that displays the complete list of related class dates in ASC order delineated by a COMMA (Group_Concat()???).

Here is a query I have started off with which show all the dates fine. Just want to fine tune it.

SELECT ic.*, i.*, DATE_FORMAT(ic.cl_date, "%M %Y") AS mo_label FROM tl_items_classes ic 
LEFT JOIN tl_items i ON ic.item_id = i.item_id 
WHERE i.active = 1 AND ic.cl_cancelled IS NULL ORDER BY ic.cl_date ASC;

Any help would be appreciated.

Don Wieland
[email protected]
http://www.pointmade.net
https://www.facebook.com/pointmade.band
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.