RE: Select Earliest Related Row
- Date: Wed, 10 Feb 2016 10:55:42 +0000
- From: Pavel Zimahorau <Pavel_Zimahorau@xxxxxxxx>
- Subject: RE: Select Earliest Related Row
ORDER BY cl_date DESC SEPARATOR ', ')
(select min(cl_date) from CLASS_DATES where item_id = c.item_id and cl_date > Now())
From CLASSES c
Join CLASS_DATES cd on (c.item_id = cd.item_id)
Group by class_name, c. item_id
I did not check it in DB and it can have some parse errors.
But It should work.
From: Don Wieland [mailto:donw@xxxxxxxxxxxxx]
Sent: Tuesday, February 09, 2016 6:57 PM
To: MySql <mysql@xxxxxxxxxxxxxxx>
Subject: Select Earliest Related Row
I have a two tables where I am adding CLASSES and CLASS_DATES for people to register for.
Table Name = tl_items (Parent)
table_name = tl_items_classes (Children)
“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.
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql