SQL Problem [message #375012] |
Wed, 18 July 2001 23:00 |
Chris
Messages: 128 Registered: November 1998
|
Senior Member |
|
|
Imagine I have a table with the columns:
PersonID (foreign key)
EventID (foreign key)
LeftEarly (boolean)
EndDate (date)
The idea is that the SQL query returns the first date each person leaves each event(someone may attend the same event twice).
Easy enough, that bit I can do with the following Statement:
SELECT MIN(StartDate) FROM table GROUP BY PersonID, EventID
However, I also want to know whether the person left early. How can make the SQL return the value of LeftEarly that corresponds the EndDate I have returned.
|
|
|
Re: SQL Problem [message #375018 is a reply to message #375012] |
Thu, 19 July 2001 02:03 |
John R
Messages: 156 Registered: March 2000
|
Senior Member |
|
|
Not a problem in Oracle, as you can't have a database column of type 'Boolean'.
However, assuming that you redesign the table, you could use:
SELECT t1.StartDate,t1.LeftEarly
FROM table t1
WHERE t1.StartDate = (SELECT min(t2.StartDate)
FROM table t2
WHERE t1.PersonId = t2.PersonId
AND t1.EventId = t2.EventId)
|
|
|