I am stuck with a MySQL table created by another developer. Its a holiday cruise table with fields like destinations, ships and sailing dates (among other fields).
Destinations Ships Sailing Dates
Antarctica MS QE2 2 Dec 2018, 1 Jan 2019
Antarctica MS TBS 2 Feb 2019, 3 Mar 2019
Antarctica MS JRB 9 Nov 2018, 5 Dec 2018
As indicated, each ship can have multiple sailing dates, entered as comma separated text. But I am interested only in the first sailing date of each row.
For example, "2 Dec 2018" is the first date on row one. Likewise, "2 Feb 2019" is the first date on row two, and so on.
I need a PHP SELECT statement to sort this entire table on the first dates of each row. To make things simpler, I thought of adding another date field to the table, and copy the first dates of each row onto that new date field, and then sort the table based on that field. But that is a round-about solution, which I don't prefer.
Is there a simple PHP/SQL statement which can achieve this? I thought of the PHP Explode() function. But I am not sure how I can incorporate that into a SELECT statement. Any help would be highly appreciated.
Update: Thanks for your suggestions. I totally agree, this table is a mess. Let's say I move the dates to a new table, with multiple rows for each row in the old table, like the following.
Destinations Ships Voyage ID
Antarctica MS QE2 1
Antarctica MS TBS 2
Antarctica MS JRB 3
Dates Table
--Voyage ID------Sailing Dates
-------1------------2 Dec 2018
-------1------------1 Jan 2019
-------2------------2 Feb 2019
-------2------------3 Mar 2019
-------3------------9 Nov 2018
-------3------------5 Dec 2018
Now, what SQL command should I use to sort the old table by the first dates of each Voyage ID in the new DATES table.