I've tried your SQL using my names but when I try to run it I get a message
saying "At most one record can be returned bt this subquery". I'm also
trying the SQL posted by Louis John but am running into a syntax error there.
Thanks so much for your help!
- Show quoted text -
The text posted at 11:30 a.m. most certainly has syntax errors.
The three most obvious are:
--There should only be a single semi-colon in the entire query;
--Single quotes should be used to specify literal values;
--and the subqueries should be enclosed with a parenthesis.
It appears more than on row meets the criterion of "Where State='SC'
AND MileageDescription='Fuel'." Therefore, you must choose one for
the query to work.
This becomes a little more complicated, but this code might work.
SELECT TripDetailsID, State, MileageDescription
from tblTripDetails
Where State='SC'
AND MileageDescription='Fuel'
AND TripDetailsID = ( select min( TripDetailsID )
from tblTripDetails
where State = 'SC'
and MileageDescription = 'Fuel' )
union
SELECT A.TripDetailsID, A.State, A.MileageDescription
from tblTripDetails as A
Where State='SC'
AND MileageDescription='Fuel'
AND TripDetailsID = ( select max( TripDetailsID )
from tblTripDetails
where State = 'SC'
and MileageDescription = 'Fuel'
and TripDetailsID < A.TripDetailsID )
Union
SELECT A.TripDetailsID, A.State, A.MileageDescription
from tblTripDetails as A
where TripDetailsID = (SELECT min(TripDetailsID )
from tblTripDetails
Where State='SC'
AND MileageDescription='Fuel'
and TripDetailsID > A.TripDetailsID )
This problem may be needlessly complicated because the TripDetailsID
only approximates the sequence that rows entered the table. The query
might return a more meaningful result if it sought the rows based on
the date of the trip.