INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Challenging SQL

Challenging SQL

(OP)

I have 2 tables

Table S
(S_rec_key  decimal (15),
 S_route    varchar (50,0)
)
primary index (s_rec_key)

Table E
(E_rec_key  decimal (15,0),
 S_rec_key  decimal(15,0),
 E_stn      varchar (3,0),
 E_dtm      timestamp
)

Table S contains information on the account and table E contains mutiple events for account. What I would like is that the field S.S_route in order of the E.E_dtm. Two events follwoing each other with the same E.E_stn are considered as one.

eg
S values (1,NULL)
S values (2, NULL)
E values (5,1,'BRU',TIMESTAMP '20070712 12:12:12')
E values (5,2,'AMS',TIMESTAMP '20070711 10:12:12')
E values (5,1,'BRU',TIMESTAMP '20070712 12:11:12')
E values (5,1,'FRA',TIMESTAMP '20070713 12:12:12')
E values (5,2,'CDG',TIMESTAMP '20070710 12:12:12')
E values (5,2,'HKG',TIMESTAMP '20070713 09:12:12')

I want a query that has as result that S looks like this:

1|'BRU,FRA'
2|'CGD,AMS,HKG'

Is this possible in pure sql?

Thanks

W

RE: Challenging SQL

May be as simple as this. Did not check the syntax and may have misunderstood the question - the key element to eliminate 'duplicates' is the distinct DML statement.

select distinct e.e_stn
from e,
     s
where e.e_s_rec_key
=     s.s_rec_key

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close