Q: How to select the first and last values for a date in SQL? I have the following query:
$sql  = "SELECT C_Date, C_Time, C_Unique FROM tEnter";
$sql .= " WHERE C_Date >= '" . $_GET['date'] . "'";

It is arranged in an ascending order based on C_Time.
Let's say for a particular date I have four results at times 8:30, 9:30, 10:30 and 11:30. How can I change the above query to just get 8:30 and 11:30 in my result?
P.S. There will be multiple dates and each date will have one or more times.

A: First of all you should change your query to avoid SQL injection. Take a look on prepare and execute statements.
Leaving on the side that I guess that if the results will be ordered by time you can just get the first and last value like this:
$first = reset($array);//to get the first value
$last = end($array);//to get the last one


A: use mysql min() and max() to select the first and last date
SELECT C_Date, MIN(C_Time) as start_time,MAX(C_Time) as end_time, C_Unique FROM tEnter WHERE DATE(C_Date) = **'DYNAMIC DATE'**

NOTE :- Change "DYNAMIC DATE" ACCORDING TO YOUR LOGIC.
Hope it will work for you.

A: You have to make self join to find MAX and MIN date
 $sql  = " SELECT t.C_Date, t.C_Time, t.C_Unique FROM tEnter as t ";
 $sql .= " JOIN (SELECT  MAX(C_Time) as formax, MIN(C_Time) as formin FROM tEnter where C_Date >= '" . $_GET['date'] . "') as tmp ON t.C_Time= tmp.formin OR t.C_Time= tmp.formax ";
 $sql .= " WHERE t.C_Date >= '" . $_GET['date'] . "'";

