SQL that returns every record twice

A

Aino

I have a table that basically holds a start time and an end time for
an event. Now I want to generate a report that returns all events
sorted by time, whether something starts or ends.

Table StartTime EndTime Event
7.00 7.30 A
7.15 8.15 B
8.00 9.30 C

Report Time Event
7.00 A
7.15 B
7.30 A
8.00 C
8.15 B
9.30 C

Can anyone help with the SQL?
 
A

Allen Browne

Use a union query.

Something like this:

SELECT StartTime AS TheTime, Event, "Start" AS EntryType FROM Table1
UNION ALL
SELECT EndTime AS TheTime, Event, "End" AS EntryType FROM Table1;
 
M

Marshall Barton

Aino said:
I have a table that basically holds a start time and an end time for
an event. Now I want to generate a report that returns all events
sorted by time, whether something starts or ends.

Table StartTime EndTime Event
7.00 7.30 A
7.15 8.15 B
8.00 9.30 C

Report Time Event
7.00 A
7.15 B
7.30 A
8.00 C
8.15 B
9.30 C


SELECT StartTime As EventTime, Event, "Start" As Action
UNION ALL
SELECT EndTime, Event, "End"
ORDER BY 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top